Permalink
Browse files

Wrapped the existing behaviour in a spec and added a pending spec for…

… the new option to validate_uniqueness_of
  • Loading branch information...
1 parent 983dd54 commit 2bf2666956ee19dd09487755b1defd5490c7b587 @mdeering committed Apr 4, 2012
Showing with 24 additions and 0 deletions.
  1. +24 −0 spec/shoulda/active_model/validate_uniqueness_of_matcher_spec.rb
@@ -140,4 +140,28 @@
@model.should validate_uniqueness_of(:attr)
end
end
+
+ context "allow protection of columns from mutation" do
+ before do
+ @model = define_model(:example, :scope1 => :integer, :magic_column => :string, :attr => :integer) do
+ validates_uniqueness_of :attr, :scope => [:scope1, :magic_column]
+
+ def magic_column=(class_string)
+ class_string.constantize
+ super
+ end
+
+ end.new
+ Example.create!(:attr => 'value', :scope1 => 1, :magic_column => 'Example')
+ end
+
+ it "should throw a NameError error when the magic column is mutated" do
+ lambda { @model.should validate_uniqueness_of(:attr).scoped_to(:scope1, :magic_column) }.should raise_error(NameError)
+ end
+
+ pending "should no longer throw a type error when we tell the matcher to skip the magic column" do
+ lambda { @model.should validate_uniqueness_of(:attr).scoped_to(:scope1, :magic_column).skip_mutation_of(:magic_column) }.should_not raise_error(NameError)
+ @model.should validate_uniqueness_of(:attr).scoped_to(:scope1, :magic_column).skip_mutation_of(:magic_column)
+ end
+ end
end

0 comments on commit 2bf2666

Please sign in to comment.