[Rails] Date Types in Unit Tests
by Steve Ross other posts by this author
Aug 29 2005 2:25PM messages near this date
Re: [Rails] AR - Bit Kurioz
|
[Rails] Re: Date Types in Unit Tests
Reposting because I didn't see this get into the list:
---
I have a MySQL database with a DATE field:
CREATE TABLE sales (
id int(11) NOT NULL auto_increment,
...
sale_date date NOT NULL default '2003-01-01',
PRIMARY KEY (id)
) ENGINE=MyISAM;
I've created a validate function in my model:
protected
def validate
errors.add(:sale_date, 'sale date cannot be later than today') if
Date.today < sale_date
end
All good if I am using the browser, but from my unit test, I do the
following:
@sale = Sale.new
...
@sale.sale_date = 1.week.ago
assert @sale.save
And get an error that I can't compare a Date and Time. Specifically,
ArgumentError: comparison of Date with Time failed
I've tried numerous variations on setting the date, but keep running into
this type error. What am I failing to see?
Thanks
_______________________________________________
Rails mailing list
Rails@[...].org
http://lists.rubyonrails.org/mailman/listinfo/rails
Thread:
Steve Ross
Michael Schuerig
Dee Zsombor
|