aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/fixtures/fake-authority-type.csv3
-rw-r--r--spec/models/public_body_spec.rb32
2 files changed, 35 insertions, 0 deletions
diff --git a/spec/fixtures/fake-authority-type.csv b/spec/fixtures/fake-authority-type.csv
new file mode 100644
index 000000000..4aa618ad1
--- /dev/null
+++ b/spec/fixtures/fake-authority-type.csv
@@ -0,0 +1,3 @@
+,North West Fake Authority,north_west_foi@localhost
+,Scottish Fake Authority,scottish_foi@localhost
+,Fake Authority of Northern Ireland,ni_foi@localhost
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index 827527213..5c58cdc54 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -85,3 +85,35 @@ describe PublicBody, "when searching" do
end
end
+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")
+ 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"]
+
+ PublicBody.count.should == original_count
+ end
+
+ it "should do full run successfully" do
+ original_count = PublicBody.count
+
+ csv_contents = load_file_fixture("fake-authority-type.csv")
+ 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"]
+
+ PublicBody.count.should == original_count + 3
+ end
+end
+
+
+