codegram / date_validator

A simple, ORM agnostic, Ruby >=2.2 compatible date validator for Rails, based on ActiveModel.
http://thoughts.codegram.com/date-validation-with-rails-3
MIT License
495 stars 82 forks source link

Mark non Date/Time objects as invalid #69

Closed yez closed 8 years ago

yez commented 8 years ago

@oriolgual @txus This should Resolve #48.

Given a test model:

class TestModel
  attr_accessor :foo
  validates :foo, date: true

  def initialize(date)
    @foo = date
  end
end

Behaviour before this patch:

m = TestModel.new('not a date')
m.valid?
=> true

Behaviour after this patch:

m = TestModel.new('not a date')
m.valid?
=> false

The only outstanding question is should a string like 2016-01-08 go through Date.parse or to_date to try and make it valid.

oriolgual commented 8 years ago

Thanks!