aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/customstates.rb20
-rw-r--r--spec/models/incoming_message_spec.rb60
-rw-r--r--spec/models/public_body_spec.rb91
-rw-r--r--spec/models/track_mailer_spec.rb1
-rw-r--r--spec/models/track_thing_spec.rb10
5 files changed, 145 insertions, 37 deletions
diff --git a/spec/models/customstates.rb b/spec/models/customstates.rb
index 406d4ead9..3488e6730 100644
--- a/spec/models/customstates.rb
+++ b/spec/models/customstates.rb
@@ -5,16 +5,6 @@ module InfoRequestCustomStates
end
# Mixin methods for InfoRequest
- def theme_display_status(status)
- if status == 'deadline_extended'
- _("Deadline extended.")
- elsif status == 'wrong_response'
- _("Wrong Response.")
- else
- raise _("unknown status ") + status
- end
- end
-
def theme_calculate_status
return 'waiting_classification' if self.awaiting_description
waiting_response = self.described_state == "waiting_response" || self.described_state == "deadline_extended"
@@ -41,6 +31,16 @@ module InfoRequestCustomStates
end
module ClassMethods
+ def theme_display_status(status)
+ if status == 'deadline_extended'
+ _("Deadline extended.")
+ elsif status == 'wrong_response'
+ _("Wrong Response.")
+ else
+ raise _("unknown status ") + status
+ end
+ end
+
def theme_extra_states
return ['deadline_extended',
'wrong_response']
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb
index 183a258af..d6923da21 100644
--- a/spec/models/incoming_message_spec.rb
+++ b/spec/models/incoming_message_spec.rb
@@ -79,11 +79,21 @@ describe IncomingMessage, " folding quoted parts of emails" do
end
describe IncomingMessage, " checking validity to reply to" do
- def test_email(email, result)
+ def test_email(result, email, return_path, autosubmitted)
@address = mock(TMail::Address)
@address.stub!(:spec).and_return(email)
+
+ @return_path = mock(TMail::ReturnPathHeader)
+ @return_path.stub!(:addr).and_return(return_path)
+
+ @autosubmitted = mock(TMail::KeywordsHeader)
+ @autosubmitted.stub!(:keys).and_return(autosubmitted)
+
@mail = mock(TMail::Mail)
@mail.stub!(:from_addrs).and_return( [ @address ] )
+ @mail.stub!(:[]).with("return-path").and_return(@return_path)
+ @mail.stub!(:[]).with("auto-submitted").and_return(@autosubmitted)
+
@incoming_message = IncomingMessage.new()
@incoming_message.stub!(:mail).and_return(@mail)
@@ -91,27 +101,63 @@ describe IncomingMessage, " checking validity to reply to" do
end
it "says a valid email is fine" do
- test_email("team@mysociety.org", true)
+ test_email(true, "team@mysociety.org", nil, [])
end
it "says postmaster email is bad" do
- test_email("postmaster@mysociety.org", false)
+ test_email(false, "postmaster@mysociety.org", nil, [])
end
it "says Mailer-Daemon email is bad" do
- test_email("Mailer-Daemon@mysociety.org", false)
+ test_email(false, "Mailer-Daemon@mysociety.org", nil, [])
end
it "says case mangled MaIler-DaemOn email is bad" do
- test_email("MaIler-DaemOn@mysociety.org", false)
+ test_email(false, "MaIler-DaemOn@mysociety.org", nil, [])
end
it "says Auto_Reply email is bad" do
- test_email("Auto_Reply@mysociety.org", false)
+ test_email(false, "Auto_Reply@mysociety.org", nil, [])
end
it "says DoNotReply email is bad" do
- test_email("DoNotReply@tube.tfl.gov.uk", false)
+ test_email(false, "DoNotReply@tube.tfl.gov.uk", nil, [])
+ end
+
+ it "says a filled-out return-path is fine" do
+ test_email(true, "team@mysociety.org", "Return-path: <foo@baz.com>", [])
+ end
+
+ it "says an empty return-path is bad" do
+ test_email(false, "team@mysociety.org", "<>", [])
+ end
+
+ it "says an auto-submitted keyword is bad" do
+ test_email(false, "team@mysociety.org", nil, ["auto-replied"])
+ end
+
+end
+
+describe IncomingMessage, " checking validity to reply to with real emails" do
+ fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users
+
+ after(:all) do
+ ActionMailer::Base.deliveries.clear
+ end
+ it "should allow a reply to plain emails" do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('incoming-request-plain.email', ir.incoming_email)
+ ir.incoming_messages[1].valid_to_reply_to?.should == true
+ end
+ it "should not allow a reply to emails with empty return-paths" do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('empty-return-path.email', ir.incoming_email)
+ ir.incoming_messages[1].valid_to_reply_to?.should == false
+ end
+ it "should not allow a reply to emails with autoresponse headers" do
+ ir = info_requests(:fancy_dog_request)
+ receive_incoming_mail('autoresponse-header.email', ir.incoming_email)
+ ir.incoming_messages[1].valid_to_reply_to?.should == false
end
end
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 3d00d37fb..9833179a7 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -227,6 +227,12 @@ describe PublicBody, "when searching" do
end
describe PublicBody, " when loading CSV files" do
+ before(:each) do
+ # InternalBody is created the first time it's accessed, which happens sometimes during imports,
+ # depending on the tag used. By accessing it here before every test, it doesn't disturb our checks later on
+ PublicBody.internal_admin_body
+ end
+
it "should do a dry run successfully" do
original_count = PublicBody.count
@@ -234,9 +240,11 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
@@ -248,10 +256,28 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
errors.should == []
notes.size.should == 3
- notes.should == ["line 1: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}"
+ ]
+
+ PublicBody.count.should == original_count + 3
+ end
+ it "should do imports without a tag successfully" do
+ original_count = PublicBody.count
+
+ csv_contents = load_file_fixture("fake-authority-type.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, '', false, 'someadmin') # false means real run
+ errors.should == []
+ notes.size.should == 4
+ notes.should == [
+ "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\"\}",
+ "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"request_email\":\"scottish_foi@localhost\"\}",
+ "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"request_email\":\"ni_foi@localhost\"\}",
+ "Notes: Some bodies are in database, but not in CSV file:\n Department for Humpadinking\n Geraldine Quango\nYou may want to delete them manually.\n"
+ ]
PublicBody.count.should == original_count + 3
end
@@ -262,27 +288,50 @@ describe PublicBody, " when loading CSV files" do
errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin') # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"\}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"tag_string\":\"scottish\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"\}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"\}"
+ ]
PublicBody.count.should == original_count
end
+
+ it "should import tags successfully when no the import tag is not set" do
+ csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, '', false, 'someadmin') # false means real run
+
+ PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == []
+ PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish']
+ PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag']
+ end
+
+ it "should import tags successfully when no the import tag is set" do
+ csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin') # false means real run
+ # XXX: when a 'tag' is set for the import, do we want to add it to the tag string for all bodies?
+ # The tests below assume we don't
+
+ PublicBody.find_by_name('North West Fake Authority').tag_array_for_search.should == []
+ PublicBody.find_by_name('Scottish Fake Authority').tag_array_for_search.should == ['scottish']
+ PublicBody.find_by_name('Fake Authority of Northern Ireland').tag_array_for_search.should == ['fake', 'aTag']
+ end
it "should create bodies with names in multiple locales" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', ['es'])
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', false, 'someadmin', [:en, :es])
errors.should == []
notes.size.should == 6
notes.should == [
- "line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 2: (aka 'Autoridad del Nordeste' in locale es)",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 3: (aka 'Autoridad Escocesa' in locale es)",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost",
- "line 4: (aka 'Autoridad Irlandesa' in locale es)"]
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 2: creating new authority 'North West Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad del Nordeste\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"tag_string\":\"scottish\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: es):\n\t{\"name\":\"Autoridad Escocesa\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}"
+ ]
PublicBody.count.should == original_count + 3
@@ -297,12 +346,14 @@ describe PublicBody, " when loading CSV files" do
original_count = PublicBody.count
csv_contents = load_file_fixture("fake-authority-type-with-field-names.csv")
- errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', ['xx']) # true means dry run
+ errors, notes = PublicBody.import_csv(csv_contents, 'fake', true, 'someadmin', [:en, :xx]) # true means dry run
errors.should == []
notes.size.should == 3
- notes.should == ["line 2: new authority 'North West Fake Authority' with email north_west_foi@localhost",
- "line 3: new authority 'Scottish Fake Authority' with email scottish_foi@localhost",
- "line 4: new authority 'Fake Authority of Northern Ireland' with email ni_foi@localhost"]
+ notes.should == [
+ "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"request_email\":\"north_west_foi@localhost\",\"home_page\":\"http://northwest.org\"}",
+ "line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"tag_string\":\"scottish\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\"}",
+ "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"tag_string\":\"fake aTag\",\"request_email\":\"ni_foi@localhost\"}"
+ ]
PublicBody.count.should == original_count
end
diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb
index 504d65144..6612641c1 100644
--- a/spec/models/track_mailer_spec.rb
+++ b/spec/models/track_mailer_spec.rb
@@ -22,6 +22,7 @@ describe TrackMailer do
:last_daily_track_email= => true,
:save! => true,
:url_name => 'test-name',
+ :get_locale => 'en',
:should_be_emailed? => true)
User.stub!(:find).and_return([@user])
@user.stub!(:no_xapian_reindex=)
diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb
index 6b9cd6d4a..1a0324a78 100644
--- a/spec/models/track_thing_spec.rb
+++ b/spec/models/track_thing_spec.rb
@@ -28,5 +28,15 @@ describe TrackThing, "when tracking changes" do
found_track.should == @track_thing
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)', "requests which are successful or unsuccessful or comments matching text 'bob'"],
+ ['(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)', 'requests which are awaiting a response']]
+ for query, description in tests
+ track_thing = TrackThing.create_track_for_search_query(query)
+ track_thing.track_query_description.should == description
+ end
+ end
+
end