Skip to content

Commit

Permalink
optimize AllowValueMatcher slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
sigi authored and Gabe Berke-Williams committed Mar 23, 2012
1 parent 8724cd2 commit 026927b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/shoulda/matchers/active_model/allow_value_matcher.rb
Expand Up @@ -58,10 +58,14 @@ def description
private

def errors_match?
@instance.valid?
@errors = errors_for_attribute(@instance, @attribute)
@errors = [@errors] unless @errors.is_a?(Array)
@expected_message ? (errors_match_regexp? || errors_match_string?) : (@errors.compact.any?)
if ! @instance.valid?
@errors = errors_for_attribute(@instance, @attribute)
@errors = [@errors] unless @errors.is_a?(Array)
@expected_message ? (errors_match_regexp? || errors_match_string?) : (@errors.compact.any?)
else
@errors = []
false
end
end

def errors_for_attribute(instance, attribute)
Expand Down

0 comments on commit 026927b

Please sign in to comment.