On 10/12/2011 08:35 PM, Chris Alfonso wrote:
I've added a catalog_id scope to the catalog_entry validation
such that a
catalog_entry can have the same name across two different catalogs.
---
src/app/models/catalog_entry.rb | 2 +-
src/spec/models/catalog_entry_spec.rb | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/app/models/catalog_entry.rb b/src/app/models/catalog_entry.rb
index 8c87b5c..6175bdf 100644
--- a/src/app/models/catalog_entry.rb
+++ b/src/app/models/catalog_entry.rb
@@ -32,7 +32,7 @@ class CatalogEntry< ActiveRecord::Base
include PermissionedObject
validates_presence_of :name
- validates_uniqueness_of :name
+ validates_uniqueness_of :name, :scope => :catalog_id
validates_length_of :name, :maximum => 1024
validates_presence_of :url
validates_format_of :url, :with => URI::regexp
diff --git a/src/spec/models/catalog_entry_spec.rb
b/src/spec/models/catalog_entry_spec.rb
index 60304b6..ba6427a 100644
--- a/src/spec/models/catalog_entry_spec.rb
+++ b/src/spec/models/catalog_entry_spec.rb
@@ -30,14 +30,24 @@ describe CatalogEntry do
end
it "should have unique name" do
- catalog_entry = FactoryGirl.create :catalog_entry
- catalog_entry2 = Factory.build(:catalog_entry, :name => catalog_entry.name)
+ catalog = FactoryGirl.create :catalog
+ catalog_entry = FactoryGirl.create :catalog_entry, :catalog => catalog
+ catalog_entry2 = Factory.build(:catalog_entry, :name => catalog_entry.name,
:catalog => catalog)
catalog_entry2.should_not be_valid
catalog_entry2.name = 'unique name'
catalog_entry2.should be_valid
end
+ it "should have a valid name across catalogs" do
+ catalog1 = FactoryGirl.create :catalog
+ catalog2 = FactoryGirl.create :catalog
+ catalog_entry1 = FactoryGirl.create :catalog_entry, :name =>"same
name", :catalog => catalog1
+ catalog_entry2 = FactoryGirl.create :catalog_entry, :name => "same
name", :catalog => catalog2
+ catalog_entry1.should be_valid
+ catalog_entry2.should be_valid
+ end
+
it "should have a url" do
catalog_entry = FactoryGirl.create :catalog_entry
catalog_entry.url = ''
ACK