Skip to content

Commit

Permalink
Clean up ValidatesNumericalityOfMatcher a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Mar 30, 2012
1 parent 3b3181b commit 4ff1344
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Shoulda # :nodoc:
module Matchers
module ActiveModel # :nodoc:

# Ensure that the attribute is numeric
#
# Options:
Expand All @@ -17,23 +16,28 @@ def validate_numericality_of(attr)
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

0 comments on commit 4ff1344

Please sign in to comment.