mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
Remove duplication in ValidationMatcher
This commit is contained in:
parent
d9289fa5c7
commit
96d32c289c
1 changed files with 17 additions and 14 deletions
|
@ -26,13 +26,8 @@ module Shoulda # :nodoc:
|
|||
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 @@ module Shoulda # :nodoc:
|
|||
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 @@ module Shoulda # :nodoc:
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue