diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-04-14 17:13:02 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-04-14 17:13:02 +0100 |
commit | fb0742f39fc9f5ba9e45ef08a4e4312ea10660f1 (patch) | |
tree | e07392141eebad88109b5e7ad62910a5bfdc4f1e /spec/models/public_body_spec.rb | |
parent | 4e74160d372fd4bca170c056944708b7cfdd2dba (diff) | |
parent | 77eba1956f318510247163133197b64f08b9c1e1 (diff) |
Merge branch 'issues/1416-csv-update-public-bodies' into rails-3-develop
Diffstat (limited to 'spec/models/public_body_spec.rb')
-rw-r--r-- | spec/models/public_body_spec.rb | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb index dc09bdfa6..38e31783d 100644 --- a/spec/models/public_body_spec.rb +++ b/spec/models/public_body_spec.rb @@ -5,7 +5,7 @@ # # id :integer not null, primary key # name :text not null -# short_name :text not null +# short_name :text default(""), not null # request_email :text not null # version :integer not null # last_edit_editor :string(255) not null @@ -205,6 +205,12 @@ describe PublicBody, " when saving" do pb.first_letter.should == 'Å' end + it "should not save if the url_name is already taken" do + existing = FactoryGirl.create(:public_body) + pb = PublicBody.new(existing.attributes) + pb.should have(1).errors_on(:url_name) + 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" @@ -527,6 +533,19 @@ describe PublicBody, " when loading CSV files" do PublicBody.count.should == original_count + 3 end + it "should handle active record validation errors" do + csv = <<-CSV +#name,request_email,short_name +Foobar,a@example.com,foobar +Foobar Test,b@example.com,foobar +CSV + + csv_contents = normalize_string_to_utf8(csv) + errors, notes = PublicBody.import_csv(csv_contents, '', 'replace', true, 'someadmin') # true means dry run + + errors.should include("error: line 3: Url name URL name is already taken for authority 'Foobar Test'") + end + end describe PublicBody do |