test/rails/macros/validates_uniqueness_test.rb in whyvalidationssuckin96-1.3.0 vs test/rails/macros/validates_uniqueness_test.rb in whyvalidationssuckin96-1.3.1
- old
+ new
@@ -66,10 +66,31 @@
work.save
work.author = "gabe"
work.save
end
end # with default options
+
+ context "uniqueness of integers" do
+ setup do
+ Class.new(Chapter) do
+ setup_validations do
+ validates_uniqueness_of :number, :scope_to => :book_id
+ end
+ end
+ end
+
+ should "not allow two objects with the same number" do
+ chapter = topic.new(:name => "A Dark and Stormy Night",
+ :number => 1, :book_id => 1)
+ chapter.save!
+ other_chapter = topic.new(:name => "Another Dark and Stormy Night",
+ :number => 1, :book_id => 1)
+ !other_chapter.valid? && other_chapter.failed_validations.detect do |fv|
+ fv.kind_of?(WhyValidationsSuckIn96::ValidatesUniqueness) && fv.attribute == :number
+ end
+ end
+ end
context "specifying case sensitivity" do
setup do
Class.new(VisualWork) do
setup_validations do
@@ -148,6 +169,6 @@
Painting.create!(:author => "myles", :name => "bitchesbrew")
end
end
end # when using with_scope
end # validating an object
-end # validates uniqueness
\ No newline at end of file
+end # validates uniqueness