Skip to content

Commit

Permalink
[thoughtbot#131] Refactor validate_presence_of_matcher
Browse files Browse the repository at this point in the history
I'll be adding a number of new options, so I'm refactoring to use options hash
so that all of the arguments can be stored in once place.
  • Loading branch information
calebhearth committed Aug 18, 2012
1 parent 63dd9f5 commit 373b0d8
Showing 1 changed file with 8 additions and 3 deletions.
Expand Up @@ -21,15 +21,20 @@ def validate_presence_of(attr)

class ValidatePresenceOfMatcher < ValidationMatcher # :nodoc:

def initialize(attribute)
super
@options = {}
end

def with_message(message)
@expected_message = message if message
@options[:expected_message] = message if message
self
end

def matches?(subject)
super(subject)
@expected_message ||= :blank
disallows_value_of(blank_value, @expected_message)
@options[:expected_message] ||= :blank
disallows_value_of(blank_value, @options[:expected_message])
end

def description
Expand Down

0 comments on commit 373b0d8

Please sign in to comment.