From 68b7df323748c892f6607a6a02fe3c1bb7fceeee Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 16 Jan 2009 16:13:57 -0800 Subject: [PATCH] Added specs to test for using the default (today) date. #1920 --- spec/models/rate_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/models/rate_spec.rb b/spec/models/rate_spec.rb index 2cc42d8..c87ed7b 100644 --- a/spec/models/rate_spec.rb +++ b/spec/models/rate_spec.rb @@ -185,4 +185,36 @@ describe Rate, 'for' do end end + + describe 'with a user and project' do + it 'should find all the rates for a user on the project before today' do + rate1 = mock_model(Rate, :amount => 50.50) + + Rate.should_receive(:find).with(:first, { + :conditions => ["user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?", + @user.id, + @project.id, + Date.today.to_s + ], + :order => 'date_in_effect DESC' + }).and_return(rate1) + Rate.for(@user, @project) + + end + + it 'should return the value of the most recent rate found' do + rate1 = mock_model(Rate, :amount => 50.50) + + Rate.should_receive(:find).with(:first, { + :conditions => ["user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?", + @user.id, + @project.id, + Date.today.to_s + ], + :order => 'date_in_effect DESC' + }).and_return(rate1) + Rate.for(@user, @project).should eql(rate1.amount) + + end + end end