Class: RSpectacular::ActiveRecord::Matchers::DatelinessMatcher

Inherits:
Object
  • Object
show all
Includes:
Shoulda::ActiveRecord::Helpers
Defined in:
lib/rspectacular/matchers/active_record/dateliness_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(date_field) ⇒ DatelinessMatcher

Returns a new instance of DatelinessMatcher.



7
8
9
10
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 7

def initialize(date_field)
  @date_field  = date_field.to_s
  @date_method = "#{date_field.to_s}=".to_sym
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 29

def description
  "should be contain a valid date"
end

#failure_messageObject



21
22
23
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 21

def failure_message
  "Expected #{@date_field} to contain a valid date, got: #{pretty_error_messages(@dateable)}"
end

#matches?(dateable) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 12

def matches?(dateable)
  @dateable = dateable
  dateable.send(@date_method, Date.today)

  dateable.valid?

  !dateable.errors[@date_field].include?("is not a valid date")
end

#negative_failure_messageObject



25
26
27
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 25

def negative_failure_message
  "Expected #{@date_field} to contain an invalid date, got: #{pretty_error_messages(@dateable)}"
end