diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/contact_validator_spec.rb | 49 | ||||
-rw-r--r-- | spec/models/info_request_batch_spec.rb | 13 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 21 | ||||
-rw-r--r-- | spec/models/spam_address_spec.rb | 59 | ||||
-rw-r--r-- | spec/models/track_thing_spec.rb | 9 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 37 |
7 files changed, 164 insertions, 25 deletions
diff --git a/spec/models/contact_validator_spec.rb b/spec/models/contact_validator_spec.rb index 9ea0fac49..0f5403967 100644 --- a/spec/models/contact_validator_spec.rb +++ b/spec/models/contact_validator_spec.rb @@ -1,8 +1,53 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') -describe ContactValidator, " when blah" do - before do +describe ContactValidator do + + describe :new do + + let(:valid_params) do + { :name => "Vinny Vanilli", + :email => "vinny@localhost", + :subject => "Why do I have such an ace name?", + :message => "You really should know!!!\n\nVinny" } + end + + it 'validates specified attributes' do + ContactValidator.new(valid_params).should be_valid + end + + it 'validates name is present' do + valid_params.except!(:name) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:name) + end + + it 'validates email is present' do + valid_params.except!(:email) + validator = ContactValidator.new(valid_params) + # We have 2 errors on email because of the format validator + expect(validator).to have(2).errors_on(:email) + end + + it 'validates email format' do + valid_params.merge!({:email => 'not-an-email'}) + validator = ContactValidator.new(valid_params) + expect(validator.errors_on(:email)).to include("Email doesn't look like a valid address") + end + + it 'validates subject is present' do + valid_params.except!(:subject) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:subject) + end + + it 'validates message is present' do + valid_params.except!(:message) + validator = ContactValidator.new(valid_params) + expect(validator).to have(1).error_on(:message) + end + end + end diff --git a/spec/models/info_request_batch_spec.rb b/spec/models/info_request_batch_spec.rb index 53158ebe2..2881e7745 100644 --- a/spec/models/info_request_batch_spec.rb +++ b/spec/models/info_request_batch_spec.rb @@ -1,3 +1,16 @@ +# == Schema Information +# +# Table name: info_request_batches +# +# id :integer not null, primary key +# title :text not null +# user_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# body :text +# sent_at :datetime +# + require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequestBatch, "when validating" do diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 9766f928f..12499f50a 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -21,6 +21,7 @@ # external_url :string(255) # attention_requested :boolean default(FALSE) # comments_allowed :boolean default(TRUE), not null +# info_request_batch_id :integer # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index dc09bdfa6..38e31783d 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -5,7 +5,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null @@ -205,6 +205,12 @@ describe PublicBody, " when saving" do pb.first_letter.should == 'Å' end + it "should not save if the url_name is already taken" do + existing = FactoryGirl.create(:public_body) + pb = PublicBody.new(existing.attributes) + pb.should have(1).errors_on(:url_name) + end + it "should save the name when renaming an existing public body" do public_body = public_bodies(:geraldine_public_body) public_body.name = "Mark's Public Body" @@ -527,6 +533,19 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count + 3 end + it "should handle active record validation errors" do + csv = <<-CSV +#name,request_email,short_name +Foobar,a@example.com,foobar +Foobar Test,b@example.com,foobar +CSV + + csv_contents = normalize_string_to_utf8(csv) + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run + + errors.should include("error: line 3: Url name URL name is already taken for authority 'Foobar Test'") + end + end describe PublicBody do diff --git a/spec/models/spam_address_spec.rb b/spec/models/spam_address_spec.rb new file mode 100644 index 000000000..f28440121 --- /dev/null +++ b/spec/models/spam_address_spec.rb @@ -0,0 +1,59 @@ +# == Schema Information +# +# Table name: spam_addresses +# +# id :integer not null, primary key +# email :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# + +require 'spec_helper' + +describe SpamAddress do + + describe :new do + + it 'requres an email address' do + SpamAddress.new().should_not be_valid + SpamAddress.new(:email => 'spam@example.org').should be_valid + end + + it 'must have a unique email address' do + existing = FactoryGirl.create(:spam_address) + SpamAddress.new(:email => existing.email).should_not be_valid + end + + end + + describe '.spam?' do + + before(:each) do + @spam_address = FactoryGirl.create(:spam_address) + end + + it 'is a spam address if the address is stored' do + SpamAddress.spam?(@spam_address.email).should be_true + end + + it 'is not a spam address if the adress is not stored' do + SpamAddress.spam?('genuine-email@example.com').should be_false + end + + describe 'when accepting an array of emails' do + + it 'is spam if any of the emails are stored' do + emails = ['genuine-email@example.com', @spam_address.email] + SpamAddress.spam?(emails).should be_true + end + + it 'is not spam if none of the emails are stored' do + emails = ['genuine-email@example.com', 'genuine-email@example.org'] + SpamAddress.spam?(emails).should be_false + end + + end + + end + +end diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb index 1c582564b..3edf2d1ad 100644 --- a/spec/models/track_thing_spec.rb +++ b/spec/models/track_thing_spec.rb @@ -51,10 +51,11 @@ describe TrackThing, "when tracking changes" do end it "will make some sane descriptions of search-based tracks" do - tests = { 'bob variety:user' => "users matching text 'bob'", - 'bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)' => "comments or requests which are successful or unsuccessful matching text 'bob'", - '(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)' => 'requests which are awaiting a response', - ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments' } + tests = { ' (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => 'all requests or comments', + 'bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment)' => "all requests or comments matching text 'bob'", + 'bob (latest_status:successful OR latest_status:partially_successful)' => "requests which are successful matching text 'bob'", + '(latest_status:successful OR latest_status:partially_successful)' => 'requests which are successful', + 'bob' => "anything matching text 'bob'" } tests.each do |query, description| track_thing = TrackThing.create_track_for_search_query(query) track_thing.track_query_description.should == description diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index b6f48dad3..c54043092 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,24 +2,25 @@ # # Table name: users # -# id :integer not null, primary key -# email :string(255) not null -# name :string(255) not null -# hashed_password :string(255) not null -# salt :string(255) not null -# created_at :datetime not null -# updated_at :datetime not null -# email_confirmed :boolean default(FALSE), not null -# url_name :text not null -# last_daily_track_email :datetime default(2000-01-01 00:00:00 UTC) -# admin_level :string(255) default("none"), not null -# ban_text :text default(""), not null -# about_me :text default(""), not null -# locale :string(255) -# email_bounced_at :datetime -# email_bounce_message :text default(""), not null -# no_limit :boolean default(FALSE), not null -# receive_email_alerts :boolean default(TRUE), not null +# id :integer not null, primary key +# email :string(255) not null +# name :string(255) not null +# hashed_password :string(255) not null +# salt :string(255) not null +# created_at :datetime not null +# updated_at :datetime not null +# email_confirmed :boolean default(FALSE), not null +# url_name :text not null +# last_daily_track_email :datetime default(Sat Jan 01 00:00:00 UTC 2000) +# admin_level :string(255) default("none"), not null +# ban_text :text default(""), not null +# about_me :text default(""), not null +# locale :string(255) +# email_bounced_at :datetime +# email_bounce_message :text default(""), not null +# no_limit :boolean default(FALSE), not null +# receive_email_alerts :boolean default(TRUE), not null +# can_make_batch_requests :boolean default(FALSE), not null # require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') |