aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGareth Rees <gareth@mysociety.org>2014-04-14 11:22:24 +0100
committerGareth Rees <gareth@mysociety.org>2014-04-14 11:22:24 +0100
commitf1fd69bff059cf0dbd4c0e543dbd9d9079ea3be8 (patch)
treeecf335fcdffe98ae5f04de6edda1ff8c628292a4
parent1062cea89abf8f7cd75355873ae0051c1d906582 (diff)
Add missing validation to PublicBody
There's a unique index on public_bodies url_name, so we should have a validation for that.
-rw-r--r--app/models/public_body.rb1
-rw-r--r--spec/models/public_body_spec.rb6
2 files changed, 7 insertions, 0 deletions
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index c1868b32c..4aaca8337 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -38,6 +38,7 @@ class PublicBody < ActiveRecord::Base
validates_presence_of :url_name, :message => N_("URL name can't be blank")
validates_uniqueness_of :short_name, :message => N_("Short name is already taken"), :allow_blank => true
+ validates_uniqueness_of :url_name, :message => N_("URL name is already taken")
validates_uniqueness_of :name, :message => N_("Name is already taken")
validate :request_email_if_requestable
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index efd170013..c443f0d6a 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -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"