ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-rails
ruby-rails
[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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved