diff --git a/spec/models/rate_spec.rb b/spec/models/rate_spec.rb index c87ed7b..261a8aa 100644 --- a/spec/models/rate_spec.rb +++ b/spec/models/rate_spec.rb @@ -218,3 +218,40 @@ describe Rate, 'for' do end end end + +describe Rate, 'for_user_project_and_date (private)' do + before(:each) do + @user = mock_model(User) + @project = mock_model(Project) + @date = '2009-01-01' + end + + it 'should find all the rates for a user on the project before the date' 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 + ], + :order => 'date_in_effect DESC' + }).and_return(rate1) + + Rate.send(:for_user_project_and_date, @user, @project, @date) + 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 + ], + :order => 'date_in_effect DESC' + }).and_return(rate1) + Rate.send(:for_user_project_and_date, @user, @project, @date).should eql(rate1) + end +end