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
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-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Company - http://primalgrasp.com Thoughts - http://deezsombor.blogspot.com
[CC''d because list messages appear to have an enormous delay currently.] On Monday 29 August 2005 05:55, Steve Ross wrote:> @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 failedTry @sale.sale_date = 1.week.ago.to_date Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn