Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bad failure messages for validate_uniqueness_of [#152 state:res…

…olved]
  • Loading branch information...
commit 1ce9339d9c452d39c60eb2fd04156104e6e133e4 1 parent dfc0af0
Gavin Stark authored jferris committed
View
2  lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb
@@ -77,9 +77,9 @@ def matches?(subject)
def find_existing
if @existing = @subject.class.find(:first)
- @failure_message = "Can't find first #{class_name}"
true
else
+ @failure_message = "Can't find first #{class_name}"
false
end
end
View
8 test/matchers/active_record/validate_uniqueness_of_matcher_test.rb
@@ -31,10 +31,16 @@ class ValidateUniquenessOfMatcherTest < Test::Unit::TestCase # :nodoc:
context "without an existing value" do
setup do
assert_nil Example.find(:first)
+ @matcher = validate_uniqueness_of(:attr)
end
should "fail to require a unique value" do
- assert_rejects validate_uniqueness_of(:attr), @model
+ assert_rejects @matcher, @model
+ end
+
+ should "alert the tester that an existing value is not present" do
+ @matcher.matches?(@model)
+ assert @matcher.negative_failure_message =~ /^Can't find first .*/
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.