spec/integration/uniqueness_validator_spec.rb in dm-validations-0.9.9 vs spec/integration/uniqueness_validator_spec.rb in dm-validations-0.9.10

- old
+ new

@@ -3,20 +3,20 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES describe DataMapper::Validate::UniquenessValidator do before do - class Organisation + class ::Organisation include DataMapper::Resource property :id, Serial property :name, String property :domain, String #, :unique => true validates_is_unique :domain, :allow_nil => true end - class User + class ::User include DataMapper::Resource property :id, Serial property :organisation_id, Integer property :user_name, String @@ -31,44 +31,44 @@ repository do Organisation.new(:id=>1, :name=>'Org One', :domain=>'taken').save Organisation.new(:id=>2, :name=>'Org Two', :domain=>'two').save - User.new(:id=>1,:organisation_id=>1,:user_name=>'guy').save + User.new(:id=>1, :organisation_id=>1, :user_name=>'guy').save end end it 'should validate the uniqueness of a value on a resource' do repository do o = Organisation.get!(1) o.should be_valid - o = Organisation.new(:id=>20,:name=>"Org Twenty", :domain=>nil) + o = Organisation.new(:id=>20, :name=>"Org Twenty", :domain=>nil) o.should be_valid o.save - o = Organisation.new(:id=>30,:name=>"Org Thirty", :domain=>nil) + o = Organisation.new(:id=>30, :name=>"Org Thirty", :domain=>nil) o.should be_valid end end it "should not even check if :allow_nil is true" do repository do o = Organisation.get!(1) o.should be_valid - o = Organisation.new(:id=>2,:name=>"Org Two", :domain=>"taken") + o = Organisation.new(:id=>2, :name=>"Org Two", :domain=>"taken") o.should_not be_valid o.errors.on(:domain).should include('Domain is already taken') - o = Organisation.new(:id=>2,:name=>"Org Two", :domain=>"not_taken") + 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 + class ::Department include DataMapper::Resource property :name, String, :key => true validates_is_unique :name auto_migrate! @@ -81,10 +81,12 @@ 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.errors.on(:user_name).should include('User name is already taken') u.should_not be_valid_for_testing_association + u.errors.on(:user_name).should include('User name is already taken') u = User.new(:id => 2, :organisation_id => 2, :user_name => 'guy') u.should be_valid_for_testing_property u.should be_valid_for_testing_association