Module: Remarkable::ActiveModel::Matchers

Defined in:
lib/remarkable/date_validator/matchers/validate_date_of_matcher.rb

Defined Under Namespace

Classes: ValidateDateOfMatcher

Instance Method Summary collapse

Instance Method Details

#validate_date_of(*attributes, &block) ⇒ Object

Ensures that the given attributes accepts only Time, Date, Symbol or Proc objects.

Options

  • :before - when supplied, checks if attributes are only valid when before given value

  • :after - when supplied, checks if attributes are only valid when after given value

  • :before_or_equal_to - when supplied, checks if attributes are only valid when before or equal to given value

  • :after_or_equal_to - when supplied, checks if attributes are only valid when after or equal to given value

  • :message - value the test expects to find in errors[:attribute]. Regexp, string or symbol. Default = I18n.translate('activerecord.errors.messages.not_a_date')

Examples

it { should validate_date_of(:expiration_date, :after => Time.now) }
it { should validate_date_of(:expiration_date, :before => Time.now) }

should_validate_date_of :bought_at, :checked_at
should_validate_date_of :bought_at, :after => Time.now

should_validate_date_of :bought_at do |m|
  m.after = Time.now
end


106
107
108
# File 'lib/remarkable/date_validator/matchers/validate_date_of_matcher.rb', line 106

def validate_date_of(*attributes, &block)
  ValidateDateOfMatcher.new(*attributes, &block).spec(self)
end