Class: Spec::Rails::Matchers::ValidateTimeliness
- Inherits:
-
Object
- Object
- Spec::Rails::Matchers::ValidateTimeliness
- Defined in:
- lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb
Constant Summary collapse
- VALIDITY_TEST_VALUES =
{ :date => {:pass => '2000-01-01', :fail => '2000-01-32'}, :time => {:pass => '12:00', :fail => '25:00'}, :datetime => {:pass => '2000-01-01 00:00:00', :fail => '2000-01-32 00:00:00'} }
- OPTION_TEST_SETTINGS =
{ :equal_to => { :method => :+, :modify_on => :invalid }, :before => { :method => :-, :modify_on => :valid }, :after => { :method => :+, :modify_on => :valid }, :on_or_before => { :method => :+, :modify_on => :invalid }, :on_or_after => { :method => :-, :modify_on => :invalid } }
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(attribute, options) ⇒ ValidateTimeliness
constructor
A new instance of ValidateTimeliness.
- #matches?(record) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(attribute, options) ⇒ ValidateTimeliness
Returns a new instance of ValidateTimeliness.
20 21 22 23 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 20 def initialize(attribute, ) @expected, @options = attribute, @validator = ValidatesTimeliness::Validator.new() end |
Instance Method Details
#description ⇒ Object
49 50 51 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 49 def description "have validated #{@type} attribute #{@expected.inspect}" end |
#failure_message ⇒ Object
41 42 43 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 41 def "expected model to validate #{@type} attribute #{@expected.inspect} with #{@last_failure}" end |
#matches?(record) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 25 def matches?(record) @record = record @type = @options[:type] valid = test_validity valid = test_option(:equal_to) if valid && @options[:equal_to] valid = test_option(:before) if valid && @options[:before] valid = test_option(:after) if valid && @options[:after] valid = test_option(:on_or_before) if valid && @options[:on_or_before] valid = test_option(:on_or_after) if valid && @options[:on_or_after] valid = test_between if valid && @options[:between] return valid end |
#negative_failure_message ⇒ Object
45 46 47 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 45 def "expected not to validate #{@type} attribute #{@expected.inspect}" end |