Re: [Rails] Date Types in Unit Tests
by Dee Zsombor other posts by this author
Aug 30 2005 8:46PM messages near this date
[Rails] Re: Date Types in Unit Tests
|
[Rails] habtm and before_destroy
You could try using 1.week.ago.to_date in the unit tests, or place a doubt on
the Dateness of sale_date ... take your pick
Steve Ross wrote:
> 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
>
--
Company - http://primalgrasp.com
Thoughts - http://deezsombor.blogspot.com
_______________________________________________
Rails mailing list
Rails@[...].org
http://lists.rubyonrails.org/mailman/listinfo/rails
Thread:
Steve Ross
Michael Schuerig
Dee Zsombor
|