class Easy::Matchers::Validations::ValidateAcceptanceOfMatcher

Public Class Methods

new(attributes) click to toggle source
Calls superclass method
# File lib/matchers/validations/acceptance_of.rb, line 9
def initialize(attributes)
  super(attributes, :acceptance)
end

Public Instance Methods

allow_blank(value = true) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 56
def allow_blank(value = true)
  options[:allow_blank] = value
  self
end
allow_nil(value = true) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 51
def allow_nil(value = true)
  options[:allow_nil] = value
  self
end
description() click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 27
def description
  "require #{ attributes.join(', ') } to be accepted"
end
if(symbol_name) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 36
def if(symbol_name)
  options[:if] = symbol_name
  self
end
matches?(subject) click to toggle source
Calls superclass method
# File lib/matchers/validations/acceptance_of.rb, line 13
def matches?(subject)
  super(subject)

  add_allow_nil_and_accept_to_options

  matched_validator = class_name.validators.detect do |validator|
    validator.kind == type &&
      validator.attributes.sort == attributes.sort &&
      validator.options.sort == options.sort
  end

  true if matched_validator
end
on(context) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 46
def on(context)
  options[:on] = context
  self
end
strict(value) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 61
def strict(value)
  options[:strict] = value
  self
end
unless(symbol_name) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 41
def unless(symbol_name)
  options[:unless] = symbol_name
  self
end
with_message(message) click to toggle source
# File lib/matchers/validations/acceptance_of.rb, line 31
def with_message(message)
  options[:message] = message
  self
end

Private Instance Methods

add_allow_nil_and_accept_to_options() click to toggle source

TODO: check :allow_nil and :accept before setting NOTE: Rails adds this to options by defaults

# File lib/matchers/validations/acceptance_of.rb, line 70
def add_allow_nil_and_accept_to_options
  options[:allow_nil] = true
  options[:accept] = '1'
end