aboutsummaryrefslogtreecommitdiffstats
path: root/spec/models/public_body_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/public_body_spec.rb')
-rw-r--r--spec/models/public_body_spec.rb78
1 files changed, 49 insertions, 29 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index d1fdd2c47..582f1430e 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
# == Schema Information
#
# Table name: public_bodies
@@ -158,36 +159,32 @@ describe PublicBody, " when saving" do
@public_body = PublicBody.new
end
+ def set_default_attributes(public_body)
+ public_body.name = "Testing Public Body"
+ public_body.short_name = "TPB"
+ public_body.request_email = "request@localhost"
+ public_body.last_edit_editor = "*test*"
+ public_body.last_edit_comment = "This is a test"
+ end
+
it "should not be valid without setting some parameters" do
@public_body.should_not be_valid
end
it "should not be valid with misformatted request email" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
+ set_default_attributes(@public_body)
@public_body.request_email = "requestBOOlocalhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
@public_body.should_not be_valid
@public_body.should have(1).errors_on(:request_email)
end
it "should save" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
+ set_default_attributes(@public_body)
@public_body.save!
end
it "should update first_letter" do
- @public_body.name = "Testing Public Body"
- @public_body.short_name = "TPB"
- @public_body.request_email = "request@localhost"
- @public_body.last_edit_editor = "*test*"
- @public_body.last_edit_comment = "This is a test"
-
+ set_default_attributes(@public_body)
@public_body.first_letter.should be_nil
@public_body.save!
@public_body.first_letter.should == 'T'
@@ -200,6 +197,26 @@ describe PublicBody, " when saving" do
public_body.name.should == "Mark's Public Body"
end
+
+ it 'should not create a new version when nothing has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ end
+
+ it 'should create a new version if something has changed' do
+ @public_body.versions.size.should == 0
+ set_default_attributes(@public_body)
+ @public_body.save!
+ @public_body.versions.size.should == 1
+ @public_body.name = 'Test'
+ @public_body.save!
+ @public_body.versions.size.should == 2
+ end
+
end
describe PublicBody, "when searching" do
@@ -289,16 +306,17 @@ describe PublicBody, " when loading CSV files" do
it "should do a dry run successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ 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 == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].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\"}",
]
- 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[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
end
@@ -306,34 +324,36 @@ describe PublicBody, " when loading CSV files" do
it "should do full run successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ 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 == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].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\"}",
]
- 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[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 + 3
+ PublicBody.count.should == original_count + 4
end
it "should do imports without a tag successfully" do
original_count = PublicBody.count
- csv_contents = load_file_fixture("fake-authority-type.csv")
+ 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 == 4
- notes[0..2].should == [
+ notes.size.should == 5
+ notes[0..3].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\"}",
]
- 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/
- PublicBody.count.should == original_count + 3
+ 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
end
it "should handle a field list and fields out of order" do