Class: RSpectacular::ActiveRecord::Matchers::DateRangeMatcher
- Inherits:
-
Object
- Object
- RSpectacular::ActiveRecord::Matchers::DateRangeMatcher
- Includes:
- Shoulda::ActiveRecord::Helpers
- Defined in:
- lib/rspectacular/matchers/active_record/date_range_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(dates) ⇒ DateRangeMatcher
constructor
A new instance of DateRangeMatcher.
- #matches?(rangeable) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(dates) ⇒ DateRangeMatcher
Returns a new instance of DateRangeMatcher.
7 8 9 10 11 12 13 |
# File 'lib/rspectacular/matchers/active_record/date_range_matcher.rb', line 7 def initialize(dates) @begin_field = dates[:from].to_s @end_field = dates[:to].to_s @begin_method = "#{dates[:from].to_s}=".to_sym @end_method = "#{dates[:to].to_s}=".to_sym end |
Instance Method Details
#description ⇒ Object
37 38 39 |
# File 'lib/rspectacular/matchers/active_record/date_range_matcher.rb', line 37 def description "should be contain a valid range for #{@rangeable_class}" end |
#failure_message ⇒ Object
29 30 31 |
# File 'lib/rspectacular/matchers/active_record/date_range_matcher.rb', line 29 def "#{@rangeable_class} should only accept a valid date range from #{@begin_field} to #{@end_field}, got: #{(@rangeable)}" end |
#matches?(rangeable) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rspectacular/matchers/active_record/date_range_matcher.rb', line 15 def matches?(rangeable) @rangeable = rangeable beginning_date = Date.today ending_date = Date.today - 1 rangeable.send(@begin_method, beginning_date) rangeable.send(@end_method, ending_date) rangeable.valid? rangeable.errors[@begin_field].include?("must be on or before #{ending_date.to_s}") && rangeable.errors[@end_field].include?("must be on or after #{beginning_date.to_s}") end |
#negative_failure_message ⇒ Object
33 34 35 |
# File 'lib/rspectacular/matchers/active_record/date_range_matcher.rb', line 33 def "#{@rangeable_class} shouldn't accept a valid date range from #{@begin_field} to #{@end_field}, got: #{(@rangeable)}" end |