Browse files

Remove duplication in ValidationMatcher

  • Loading branch information...
1 parent d9289fa commit 96d32c289c182eada9a8c39b6cae9182e7f03630 @jferris jferris committed Sep 12, 2012
Showing with 17 additions and 14 deletions.
  1. +17 −14 lib/shoulda/matchers/active_model/validation_matcher.rb
View
31 lib/shoulda/matchers/active_model/validation_matcher.rb
@@ -26,13 +26,8 @@ def matches?(subject)
private
def allows_value_of(value, message = nil)
- allow = AllowValueMatcher.
- new(value).
- for(@attribute).
- with_message(message)
- if strict?
- allow = allow.strict
- end
+ allow = allow_value_matcher(value, message)
+
if allow.matches?(@subject)
@negative_failure_message = allow.failure_message
true
@@ -43,13 +38,8 @@ def allows_value_of(value, message = nil)
end
def disallows_value_of(value, message = nil)
- disallow = AllowValueMatcher.
- new(value).
- for(@attribute).
- with_message(message)
- if strict?
- disallow = disallow.strict
- end
+ disallow = allow_value_matcher(value, message)
+
if disallow.matches?(@subject)
@failure_message = disallow.negative_failure_message
false
@@ -59,6 +49,19 @@ def disallows_value_of(value, message = nil)
end
end
+ def allow_value_matcher(value, message)
+ matcher = AllowValueMatcher.
+ new(value).
+ for(@attribute).
+ with_message(message)
+
+ if strict?
+ matcher.strict
+ else
+ matcher
+ end
+ end
+
def strict?
@strict
end

0 comments on commit 96d32c2

Please sign in to comment.