spec/integration/uniqueness_validator_spec.rb in dm-validations-0.9.3 vs spec/integration/uniqueness_validator_spec.rb in dm-validations-0.9.4
- old
+ new
@@ -63,9 +63,23 @@
o = Organisation.new(:id=>2,:name=>"Org Two", :domain=>"not_taken")
o.should be_valid
end
end
+ it 'should validate uniqueness on a string key' do
+ class Department
+ include DataMapper::Resource
+ property :name, String, :key => true
+
+ validates_is_unique :name
+ auto_migrate!
+ end
+
+ hr = Department.create(:name => "HR")
+ hr2 = Department.new(:name => "HR")
+ hr2.valid?.should == false
+ end
+
it 'should validate the uniqueness of a value with scope' do
repository do
u = User.new(:id => 2, :organisation_id=>1, :user_name => 'guy')
u.should_not be_valid_for_testing_property
u.should_not be_valid_for_testing_association