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
- @@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'} }
Instance Method Summary collapse
- #compile_error_messages ⇒ Object
- #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.
13 14 15 16 17 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 13 def initialize(attribute, ) @expected, @options = attribute, @validator = ValidatesTimeliness::Validator.new() end |
Instance Method Details
#compile_error_messages ⇒ Object
19 20 21 22 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 19 def = validator.send(:error_messages) @messages = .inject({}) {|h, (k, v)| h[k] = v.gsub(/ (\%s|\{\{\w*\}\})/, ''); h } end |
#description ⇒ Object
50 51 52 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 50 def description "have validated #{[:type]} attribute #{expected.inspect}" end |
#failure_message ⇒ Object
42 43 44 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 42 def "expected model to validate #{[:type]} attribute #{expected.inspect} with #{last_failure}" end |
#matches?(record) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 24 def matches?(record) @record = record type = [:type] invalid_value = @@test_values[type][:fail] valid_value = parse_and_cast(@@test_values[type][:pass]) valid = error_matching(invalid_value, /#{["invalid_#{type}".to_sym]}/) && no_error_matching(valid_value, /#{["invalid_#{type}".to_sym]}/) valid = test_option(:before, :-) if [:before] && valid valid = test_option(:after, :+) if [:after] && valid valid = test_option(:on_or_before, :+, :modify_on => :invalid) if [:on_or_before] && valid valid = test_option(:on_or_after, :-, :modify_on => :invalid) if [:on_or_after] && valid return valid end |
#negative_failure_message ⇒ Object
46 47 48 |
# File 'lib/validates_timeliness/spec/rails/matchers/validate_timeliness.rb', line 46 def "expected not to validate #{[:type]} attribute #{expected.inspect}" end |