Skip to content
This repository
Browse code

Remove duplication in ValidationMatcher

  • Loading branch information...
commit 96d32c289c182eada9a8c39b6cae9182e7f03630 1 parent d9289fa
Joe Ferris jferris authored

Showing 1 changed file with 17 additions and 14 deletions. Show diff stats Hide diff stats

  1. +17 14 lib/shoulda/matchers/active_model/validation_matcher.rb
31 lib/shoulda/matchers/active_model/validation_matcher.rb
@@ -26,13 +26,8 @@ def matches?(subject)
26 26 private
27 27
28 28 def allows_value_of(value, message = nil)
29   - allow = AllowValueMatcher.
30   - new(value).
31   - for(@attribute).
32   - with_message(message)
33   - if strict?
34   - allow = allow.strict
35   - end
  29 + allow = allow_value_matcher(value, message)
  30 +
36 31 if allow.matches?(@subject)
37 32 @negative_failure_message = allow.failure_message
38 33 true
@@ -43,13 +38,8 @@ def allows_value_of(value, message = nil)
43 38 end
44 39
45 40 def disallows_value_of(value, message = nil)
46   - disallow = AllowValueMatcher.
47   - new(value).
48   - for(@attribute).
49   - with_message(message)
50   - if strict?
51   - disallow = disallow.strict
52   - end
  41 + disallow = allow_value_matcher(value, message)
  42 +
53 43 if disallow.matches?(@subject)
54 44 @failure_message = disallow.negative_failure_message
55 45 false
@@ -59,6 +49,19 @@ def disallows_value_of(value, message = nil)
59 49 end
60 50 end
61 51
  52 + def allow_value_matcher(value, message)
  53 + matcher = AllowValueMatcher.
  54 + new(value).
  55 + for(@attribute).
  56 + with_message(message)
  57 +
  58 + if strict?
  59 + matcher.strict
  60 + else
  61 + matcher
  62 + end
  63 + end
  64 +
62 65 def strict?
63 66 @strict
64 67 end

0 comments on commit 96d32c2

Please sign in to comment.
Something went wrong with that request. Please try again.