2014-04-16 06:24:02 +00:00
|
|
|
require 'forwardable'
|
|
|
|
|
2014-01-23 18:07:36 +00:00
|
|
|
module Shoulda
|
2012-10-16 17:45:06 +00:00
|
|
|
module Matchers
|
2014-01-23 18:07:36 +00:00
|
|
|
module ActiveModel
|
|
|
|
# @private
|
|
|
|
class DisallowValueMatcher
|
2014-04-16 06:24:02 +00:00
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
def_delegators :allow_matcher, :_after_setting_value
|
2012-10-16 17:45:06 +00:00
|
|
|
def initialize(value)
|
2012-10-23 16:30:18 +00:00
|
|
|
@allow_matcher = AllowValueMatcher.new(value)
|
2012-10-16 17:45:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def matches?(subject)
|
|
|
|
!@allow_matcher.matches?(subject)
|
|
|
|
end
|
|
|
|
|
|
|
|
def for(attribute)
|
|
|
|
@allow_matcher.for(attribute)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-07-02 02:16:32 +00:00
|
|
|
def on(context)
|
|
|
|
@allow_matcher.on(context)
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-07-24 21:46:01 +00:00
|
|
|
def with_message(message, options={})
|
|
|
|
@allow_matcher.with_message(message, options)
|
2012-10-16 17:45:06 +00:00
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2013-12-24 11:24:27 +00:00
|
|
|
def failure_message
|
|
|
|
@allow_matcher.failure_message_when_negated
|
2012-10-16 17:45:06 +00:00
|
|
|
end
|
2013-12-24 11:24:27 +00:00
|
|
|
alias failure_message_for_should failure_message
|
2012-10-16 17:45:06 +00:00
|
|
|
|
2013-12-24 11:24:27 +00:00
|
|
|
def failure_message_when_negated
|
|
|
|
@allow_matcher.failure_message
|
2013-03-27 18:13:46 +00:00
|
|
|
end
|
2013-12-24 11:24:27 +00:00
|
|
|
alias failure_message_for_should_not failure_message_when_negated
|
2013-03-27 18:13:46 +00:00
|
|
|
|
|
|
|
def strict
|
|
|
|
@allow_matcher.strict
|
|
|
|
self
|
|
|
|
end
|
2014-04-16 06:24:02 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :allow_matcher
|
2012-10-16 17:45:06 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|