diff options
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/incoming_message_spec.rb | 29 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 8 | ||||
-rw-r--r-- | spec/models/public_body_spec.rb | 51 | ||||
-rw-r--r-- | spec/models/track_mailer_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/xapian_spec.rb | 14 |
5 files changed, 74 insertions, 34 deletions
diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index d6923da21..a8411bc34 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -1,7 +1,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe IncomingMessage, " when dealing with incoming mail" do - fixtures :incoming_messages, :raw_emails, :info_requests + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @im = incoming_messages(:useless_incoming_message) @@ -17,6 +17,27 @@ describe IncomingMessage, " when dealing with incoming mail" do TMail::Address.parse(em) end + it "should correctly fold various types of footer" do + Dir.glob(File.join(Spec::Runner.configuration.fixture_path, "files", "email-folding-example-*.txt")).each do |file| + message = File.read(file) + parsed = IncomingMessage.remove_quoted_sections(message) + expected = File.read("#{file}.expected") + parsed.should include(expected) + end + end + + it "should fold multiline sections" do + { + "foo\n--------\nconfidential" => "foo\nFOLDED_QUOTED_SECTION\n", # basic test + "foo\n--------\nbar - confidential" => "foo\nFOLDED_QUOTED_SECTION\n", # allow scorechar inside folded section + "foo\n--------\nbar\n--------\nconfidential" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\n", # don't assume that anything after a score is a folded section + "foo\n--------\nbar\n--------\nconfidential\n--------\nrest" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\nrest", # don't assume that a folded section continues to the end of the message + "foo\n--------\nbar\n- - - - - - - -\nconfidential\n--------\nrest" => "foo\n--------\nbar\nFOLDED_QUOTED_SECTION\nrest", # allow spaces in the score + }.each do |input,output| + IncomingMessage.remove_quoted_sections(input).should == output + end + end + end describe IncomingMessage, "when parsing HTML mail" do @@ -139,7 +160,7 @@ describe IncomingMessage, " checking validity to reply to" do 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 + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages after(:all) do ActionMailer::Base.deliveries.clear @@ -163,7 +184,7 @@ describe IncomingMessage, " checking validity to reply to with real emails" do end describe IncomingMessage, " when censoring data" do - fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @test_data = "There was a mouse called Stilton, he wished that he was blue." @@ -273,7 +294,7 @@ describe IncomingMessage, " when censoring data" do end describe IncomingMessage, " when censoring whole users" do - fixtures :incoming_messages, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :users + fixtures :users, :raw_emails, :public_bodies, :public_body_translations, :info_requests, :incoming_messages before(:each) do @test_data = "There was a mouse called Stilton, he wished that he was blue." diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index b82052a0f..d50d6dace 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe InfoRequest do describe "guessing a request from an email" do - fixtures :info_requests, :public_bodies, :incoming_messages, :raw_emails + fixtures :public_bodies, :info_requests, :raw_emails, :incoming_messages before(:each) do @im = incoming_messages(:useless_incoming_message) @@ -74,7 +74,7 @@ describe InfoRequest do describe " when emailing" do - fixtures :info_requests, :info_request_events, :outgoing_messages, :public_bodies, :public_body_translations, :users, :comments + fixtures :public_bodies, :public_body_translations, :users, :info_requests, :outgoing_messages, :info_request_events, :comments before do @info_request = info_requests(:fancy_dog_request) @@ -154,7 +154,7 @@ describe InfoRequest do end describe "when calculating the status" do - fixtures :info_requests, :info_request_events, :holidays, :public_bodies, :public_body_translations, :outgoing_messages + fixtures :holidays, :public_bodies, :public_body_translations, :info_requests, :outgoing_messages, :info_request_events before do @ir = info_requests(:naughty_chicken_request) @@ -231,7 +231,7 @@ describe InfoRequest do describe "when calculating the status for a school" do - fixtures :info_requests, :info_request_events, :holidays, :public_bodies, :public_body_translations + fixtures :holidays, :public_bodies, :public_body_translations, :info_requests, :info_request_events before do @ir = info_requests(:naughty_chicken_request) diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index d2b10d493..33ab8ffdb 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -233,6 +233,16 @@ describe PublicBody, " when loading CSV files" do PublicBody.internal_admin_body end + it "should import even if no email is provided" do + errors, notes = PublicBody.import_csv("1,aBody", '', 'replace', true, 'someadmin') # true means dry run + errors.should == [] + notes.size.should == 2 + notes.should == [ + "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}", + "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" + ] + end + it "should do a dry run successfully" do original_count = PublicBody.count @@ -241,9 +251,9 @@ describe PublicBody, " when loading CSV files" do 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\"\}", + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"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" ] @@ -258,9 +268,9 @@ describe PublicBody, " when loading CSV files" do 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\"\}", + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"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" ] @@ -275,9 +285,9 @@ describe PublicBody, " when loading CSV files" do 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\"\}", + "line 1: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"request_email\":\"north_west_foi@localhost\"\}", + "line 2: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\"\}", + "line 3: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"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 @@ -291,9 +301,9 @@ describe PublicBody, " when loading CSV files" do errors.should == [] notes.size.should == 4 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\"\}", + "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t\{\"name\":\"North West Fake Authority\",\"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\",\"name\":\"Scottish Fake Authority\",\"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\",\"name\":\"Fake Authority of Northern Ireland\",\"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" ] @@ -345,11 +355,11 @@ describe PublicBody, " when loading CSV files" do errors.should == [] notes.size.should == 7 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 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"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: en):\n\t{\"tag_string\":\"scottish\",\"name\":\"Scottish Fake Authority\",\"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: en):\n\t{\"tag_string\":\"fake aTag\",\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\"}", "line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}", "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" ] @@ -367,13 +377,16 @@ 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, '', 'replace', true, 'someadmin', [:en, :xx]) # true means dry run + # Depending on the runtime environment (Ruby version? OS?) the list of available locales + # is made of strings or symbols, so we use 'en' here as a string to test both scenarios. + # See https://github.com/sebbacon/alaveteli/issues/193 + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin', ['en', :xx]) # true means dry run errors.should == [] notes.size.should == 4 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\"}", + "line 2: creating new authority 'North West Fake Authority' (locale: en):\n\t{\"name\":\"North West Fake Authority\",\"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\",\"name\":\"Scottish Fake Authority\",\"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\",\"name\":\"Fake Authority of Northern Ireland\",\"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" ] diff --git a/spec/models/track_mailer_spec.rb b/spec/models/track_mailer_spec.rb index 6612641c1..67a64ee10 100644 --- a/spec/models/track_mailer_spec.rb +++ b/spec/models/track_mailer_spec.rb @@ -45,6 +45,9 @@ describe TrackMailer do @user.should_receive(:save!) TrackMailer.alert_tracks end + it 'should return true' do + TrackMailer.alert_tracks.should == true + end describe 'for each tracked thing' do @@ -139,6 +142,9 @@ describe TrackMailer do @user.should_not_receive(:save!) TrackMailer.alert_tracks end + it 'should return false' do + TrackMailer.alert_tracks.should == false + end end end diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb index 0c6fa6bb6..51d410660 100644 --- a/spec/models/xapian_spec.rb +++ b/spec/models/xapian_spec.rb @@ -34,7 +34,7 @@ describe User, " when indexing users with Xapian" do end describe PublicBody, " when indexing public bodies with Xapian" do - fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments, :info_requests + fixtures :public_bodies, :public_body_translations, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments before(:each) do load_raw_emails_data(raw_emails) end @@ -72,7 +72,7 @@ describe PublicBody, " when indexing public bodies with Xapian" do end describe PublicBody, " when indexing requests by body they are to" do - fixtures :public_bodies, :public_body_translations, :info_request_events, :info_requests, :raw_emails, :comments + fixtures :public_bodies, :public_body_translations, :info_requests, :raw_emails, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) @@ -132,7 +132,7 @@ describe PublicBody, " when indexing requests by body they are to" do end describe User, " when indexing requests by user they are from" do - fixtures :users, :info_request_events, :info_requests, :incoming_messages, :outgoing_messages, :raw_emails, :comments + fixtures :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) end @@ -219,7 +219,7 @@ describe User, " when indexing requests by user they are from" do end describe User, " when indexing comments by user they are by" do - fixtures :users, :info_request_events, :info_requests, :comments, :incoming_messages, :outgoing_messages, :raw_emails, :comments + fixtures :users, :info_requests, :raw_emails, :incoming_messages, :outgoing_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) end @@ -256,7 +256,7 @@ describe User, " when indexing comments by user they are by" do end describe InfoRequest, " when indexing requests by their title" do - fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments + fixtures :info_requests, :raw_emails, :incoming_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) end @@ -287,7 +287,7 @@ describe InfoRequest, " when indexing requests by their title" do end describe InfoRequest, " when indexing requests by tag" do - fixtures :info_request_events, :info_requests, :incoming_messages, :raw_emails, :comments + fixtures :info_requests, :raw_emails, :incoming_messages, :comments, :info_request_events before(:each) do load_raw_emails_data(raw_emails) end @@ -309,7 +309,7 @@ describe InfoRequest, " when indexing requests by tag" do end describe PublicBody, " when indexing authorities by tag" do - fixtures :public_bodies, :public_body_translations, :incoming_messages, :outgoing_messages, :raw_emails, :comments + fixtures :public_bodies, :public_body_translations, :raw_emails, :incoming_messages, :outgoing_messages, :comments before(:each) do load_raw_emails_data(raw_emails) end |