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
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

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