From 026927b324d67bb1e56b269b372c052479bb662f Mon Sep 17 00:00:00 2001 From: Frank Luithle Date: Sun, 5 Sep 2010 17:23:09 +0200 Subject: [PATCH] optimize AllowValueMatcher slightly --- .../matchers/active_model/allow_value_matcher.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/shoulda/matchers/active_model/allow_value_matcher.rb b/lib/shoulda/matchers/active_model/allow_value_matcher.rb index 96853035a..a9021fedc 100644 --- a/lib/shoulda/matchers/active_model/allow_value_matcher.rb +++ b/lib/shoulda/matchers/active_model/allow_value_matcher.rb @@ -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)