aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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"