Clean up ValidatesNumericalityOfMatcher a bit.

This commit is contained in:
Gabe Berke-Williams 2012-03-30 10:36:55 -04:00
parent 3b3181b11a
commit 4ff1344c2d
1 changed files with 10 additions and 6 deletions

View File

@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActiveModel # :nodoc:
# Ensure that the attribute is numeric
#
# Options:
@ -17,23 +16,28 @@ module Shoulda # :nodoc:
end
class ValidateNumericalityOfMatcher < ValidationMatcher # :nodoc:
def with_message(message)
@expected_message = message if message
if message
@expected_message = message
end
self
end
def matches?(subject)
super(subject)
@expected_message ||= :not_a_number
disallows_value_of('abcd', @expected_message)
disallows_value_of('abcd', expected_message)
end
def description
"only allow numeric values for #{@attribute}"
end
end
private
def expected_message
@expected_message || :not_a_number
end
end
end
end
end