aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/info_request_spec.rb10
-rw-r--r--spec/models/outgoing_message_spec.rb2
-rw-r--r--spec/models/public_body_spec.rb44
-rw-r--r--spec/models/xapian_spec.rb23
4 files changed, 44 insertions, 35 deletions
diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb
index 7281b74b6..64ad1972e 100644
--- a/spec/models/info_request_spec.rb
+++ b/spec/models/info_request_spec.rb
@@ -770,6 +770,16 @@ describe InfoRequest do
end
end
+ describe 'when working out a subject for request emails' do
+
+ it 'should create a standard request subject' do
+ info_request = FactoryGirl.build(:info_request)
+ expected_text = "Freedom of Information request - #{info_request.title}"
+ info_request.email_subject_request.should == expected_text
+ end
+
+ end
+
describe 'when working out a subject for a followup emails' do
it "should not be confused by an nil subject in the incoming message" do
diff --git a/spec/models/outgoing_message_spec.rb b/spec/models/outgoing_message_spec.rb
index 20f07e8fe..8c000665b 100644
--- a/spec/models/outgoing_message_spec.rb
+++ b/spec/models/outgoing_message_spec.rb
@@ -144,7 +144,7 @@ describe OutgoingMessage, " when making an outgoing message" do
end
-describe IncomingMessage, " when censoring data" do
+describe OutgoingMessage, " when censoring data" do
before do
@om = outgoing_messages(:useless_outgoing_message)
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 582f1430e..7a2c60722 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -190,6 +190,17 @@ describe PublicBody, " when saving" do
@public_body.first_letter.should == 'T'
end
+ it "should update first letter, even if it's a multibyte character" do
+ pb = PublicBody.new(:name => 'åccents, lower-case',
+ :short_name => 'ALC',
+ :request_email => 'foo@localhost',
+ :last_edit_editor => 'test',
+ :last_edit_comment => '')
+ pb.first_letter.should be_nil
+ pb.save!
+ pb.first_letter.should == 'Å'
+ 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"
@@ -300,7 +311,7 @@ describe PublicBody, " when loading CSV files" do
errors.should == []
notes.size.should == 2
notes[0].should == "line 1: creating new authority 'aBody' (locale: en):\n\t{\"name\":\"aBody\"}"
- notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[1].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
end
it "should do a dry run successfully" do
@@ -309,14 +320,15 @@ describe PublicBody, " when loading CSV files" do
csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run
errors.should == []
- notes.size.should == 5
- notes[0..3].should == [
+ notes.size.should == 6
+ notes[0..4].should == [
"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\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
+ "line 5: creating new authority 'Nordic æøå' (locale: en):\n\t{\"name\":\"Nordic \\u00e6\\u00f8\\u00e5\",\"request_email\":\"no_foi@localhost\"}"
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[5].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -327,16 +339,17 @@ describe PublicBody, " when loading CSV files" do
csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
- notes.size.should == 5
- notes[0..3].should == [
+ notes.size.should == 6
+ notes[0..4].should == [
"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\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
+ "line 5: creating new authority 'Nordic æøå' (locale: en):\n\t{\"name\":\"Nordic \\u00e6\\u00f8\\u00e5\",\"request_email\":\"no_foi@localhost\"}"
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[5].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
- PublicBody.count.should == original_count + 4
+ PublicBody.count.should == original_count + 5
end
it "should do imports without a tag successfully" do
@@ -345,15 +358,16 @@ describe PublicBody, " when loading CSV files" do
csv_contents = normalize_string_to_utf8(load_file_fixture("fake-authority-type.csv"))
errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', false, 'someadmin') # false means real run
errors.should == []
- notes.size.should == 5
- notes[0..3].should == [
+ notes.size.should == 6
+ notes[0..4].should == [
"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\"\}",
"line 4: creating new authority 'Gobierno de Aragón' (locale: en):\n\t\{\"name\":\"Gobierno de Arag\\u00f3n\",\"request_email\":\"spain_foi@localhost\"}",
+ "line 5: creating new authority 'Nordic æøå' (locale: en):\n\t{\"name\":\"Nordic \\u00e6\\u00f8\\u00e5\",\"request_email\":\"no_foi@localhost\"}"
]
- notes[4].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
- PublicBody.count.should == original_count + 4
+ notes[5].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
+ PublicBody.count.should == original_count + 5
end
it "should handle a field list and fields out of order" do
@@ -368,7 +382,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t\{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"\}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t\{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"\}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
@@ -425,7 +439,7 @@ describe PublicBody, " when loading CSV files" do
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: es):\n\t{\"name\":\"Autoridad Irlandesa\"}",
]
- notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[6].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count + 3
@@ -451,7 +465,7 @@ describe PublicBody, " when loading CSV files" do
"line 3: creating new authority 'Scottish Fake Authority' (locale: en):\n\t{\"name\":\"Scottish Fake Authority\",\"request_email\":\"scottish_foi@localhost\",\"home_page\":\"http://scottish.org\",\"tag_string\":\"scottish\"}",
"line 4: creating new authority 'Fake Authority of Northern Ireland' (locale: en):\n\t{\"name\":\"Fake Authority of Northern Ireland\",\"request_email\":\"ni_foi@localhost\",\"tag_string\":\"fake aTag\"}",
]
- notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( [A-Za-z ]+\n)*You may want to delete them manually.\n/
+ notes[3].should =~ /Notes: Some bodies are in database, but not in CSV file:\n( .+\n)*You may want to delete them manually.\n/
PublicBody.count.should == original_count
end
diff --git a/spec/models/xapian_spec.rb b/spec/models/xapian_spec.rb
index c7c21e3a0..3c9fff784 100644
--- a/spec/models/xapian_spec.rb
+++ b/spec/models/xapian_spec.rb
@@ -406,28 +406,13 @@ describe InfoRequestEvent, " when faced with a race condition during xapian_mark
before(:each) do
load_raw_emails_data
get_fixtures_xapian_index
- # Use the before create job hook to simulate a race condition with another process
- # by creating an acts_as_xapian_job record for the same model
- class InfoRequestEvent
- def xapian_before_create_job_hook(action, model, model_id)
- ActsAsXapian::ActsAsXapianJob.create!(:model => model,
- :model_id => model_id,
- :action => action)
- end
- end
- end
-
- after(:each) do
- # Reset the before create job hook
- class InfoRequestEvent
- def xapian_before_create_job_hook(action, model, model_id)
- end
- end
end
it 'should not raise an error but should fail silently' do
- ir = info_requests(:naughty_chicken_request)
- ir.reindex_request_events
+ with_duplicate_xapian_job_creation do
+ ir = info_requests(:naughty_chicken_request)
+ ir.reindex_request_events
+ end
end
end