Class: Mongoid::Matchers::Validations::ValidateAcceptanceMatcher

Inherits:
HaveValidationMatcher show all
Defined in:
lib/matchers/validations/acceptance.rb

Instance Method Summary collapse

Methods inherited from HaveValidationMatcher

#failure_message, #negative_failure_message, #with_message

Methods included from Helpers

#class_of, #to_sentence

Constructor Details

#initialize(field) ⇒ ValidateAcceptanceMatcher

Returns a new instance of ValidateAcceptanceMatcher.



5
6
7
# File 'lib/matchers/validations/acceptance.rb', line 5

def initialize(field)
  super(field, :acceptance)
end

Instance Method Details

#accept_with(value) ⇒ Object



9
10
11
12
# File 'lib/matchers/validations/acceptance.rb', line 9

def accept_with(value)
  @accepted = value
  self
end

#descriptionObject



22
23
24
25
26
# File 'lib/matchers/validations/acceptance.rb', line 22

def description
  desc = []
  desc << " accept with #{@accepted.inspect}" if @accepted
  super << desc.to_sentence
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/matchers/validations/acceptance.rb', line 14

def matches?(subject)
  return false unless @result = super(subject)
  
  check_accepted_value if @accepted

  @result
end