Class: Shoulda::Matchers::ActiveModel::ValidateTimelinessMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute, date_type) ⇒ ValidateTimelinessMatcher

Returns a new instance of ValidateTimelinessMatcher.



10
11
12
13
14
# File 'lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb', line 10

def initialize(attribute, date_type)
  @attribute = attribute
  @date_type = date_type
  @options = {}
end

Instance Method Details

#descriptionObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb', line 40

def description
  description = "ensure #{@attribute} has a valid #{@date_type} "
  %w(before on_or_before after on_or_after between).each do |validator|
    symbolized_validator = validator.to_sym
    if @options.key?(symbolized_validator)
      description << "#{validator.tr('_', ' ')} #{@options[symbolized_validator]}"
    end
  end
  description
end

#failure_messageObject Also known as: failure_message_for_should



30
31
32
# File 'lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb', line 30

def failure_message
  "Expected #{expectation} (#{@missing})"
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



35
36
37
# File 'lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb', line 35

def failure_message_when_negated
  "Did not expect #{expectation}"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/beyond_the_api_test_helpers/shoulda/validate_timeliness.rb', line 25

def matches?(subject)
  @subject = subject
  valid_date_according_to_type? && valid_date_according_to_options?
end