Validating one date is after the other doesn't seem to work #29

Closed
Haar opened this Issue Mar 23, 2012 · 1 comment

Comments

Projects
None yet
3 participants

Haar commented Mar 23, 2012

I'm running Ruby 1.9.3-p0, with Rails 3.1.3 on OS X 10.6.8.

My model contains the following:

validates_presence_of :start_date, :end_date
validates :start_date, :date => { :before => Time.now + 1.week }
validates :end_date, :date => { :after => :start_date }

However when I try checking this functionality, I get the following error message:

1.9.3p0 :037 > report = Report.new(start_date: "10/01/2012", end_date: "11/01/2012")
 => #<Report end_date: "11/01/2012", start_date: "10/01/2012"> 
1.9.3p0 :038 > report.valid?
 => false 
1.9.3p0 :039 > report.errors
 => #<ActiveModel::Errors:0x0000010285fa90 @base=#<Report end_date: "11/01/2012", start_date: "10/01/2012">,   @messages={:end_date=>["must be after 10/01/2012"]}>

When making a string comparison of "10/01/2012" < "11/01/2012" it returns true, or a date comparison of Date.parse("10/01/2012") < Date.parse("11/01/2012") it returns true as well.

Owner

txus commented Sep 14, 2012

Nice catch! Strange... want to give a try at fixing it?

oriolgual closed this Mar 29, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment