Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 2.3.11 DateTime BigDecimal Precision

I currently have a project in Ruby on Rails running Ruby 1.8.7 and Rails 2.3.2

I have some unit tests that read data from a database, specifically a date time column for two consecutive items which are supposed to be 24 hours apart. In one test I am setting the datetime for item 2 equal to that of item 1.

When I do an assert to make sure the two values are equal, the test works fine under rails 2.3.2. When I upgrade to rails 2.3.11, the tests fails showing that the difference between the two times to be off with the following error:

<Thu, 01 Jan 2009 06:00:00 CST -06:00> expected but was
<Thu, 01 Jan 2009 05:59:59 CST -06:00>.

There seems to be an issue with floating point conversions in the two version of rails. How can I account for the floating point issue?

like image 813
Daven Patel Avatar asked Apr 05 '11 01:04

Daven Patel


1 Answers

This has happened to me too, and I ended up doing this:

datetime.should be_a(Datetime) # maybe unnecessary
datetime.to_s.should == expected_datetime.to_s
like image 58
Zubin Avatar answered Oct 09 '22 22:10

Zubin