Rate#for will now return the most current rate for the user matching the parameters. #1920
This commit is contained in:
1 parent
b59c87b1f6
commit
6a211c3e5e
2 files changed
+21
-4
No files matched your search
+3
-1
@@ -33,6 +33,8 @@ class Rate < ActiveRecord::Base
|
|||||||
date
|
date
|
||||||
],
|
],
|
||||||
:order => 'date_in_effect DESC')
|
:order => 'date_in_effect DESC')
|
||||||
nil
|
|
||||||
|
return nil if rates.empty?
|
||||||
|
return rates[0].amount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -156,8 +156,8 @@ describe Rate, 'for' do
|
|||||||
|
|
||||||
describe 'with a user, project, and date' do
|
describe 'with a user, project, and date' do
|
||||||
it 'should find all the rates for a user on the project before the date' do
|
it 'should find all the rates for a user on the project before the date' do
|
||||||
rate1 = mock_model(Rate)
|
rate1 = mock_model(Rate, :amount => 50.50)
|
||||||
rate2 = mock_model(Rate)
|
rate2 = mock_model(Rate, :amount => 100.25)
|
||||||
rates = [rate1, rate2]
|
rates = [rate1, rate2]
|
||||||
|
|
||||||
Rate.should_receive(:find).with(:all, {
|
Rate.should_receive(:find).with(:all, {
|
||||||
@@ -172,6 +172,21 @@ describe Rate, 'for' do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should return the value of the most recent rate found'
|
it 'should return the value of the most recent rate found' do
|
||||||
|
rate1 = mock_model(Rate, :amount => 50.50)
|
||||||
|
rate2 = mock_model(Rate, :amount => 100.25)
|
||||||
|
rates = [rate1, rate2]
|
||||||
|
|
||||||
|
Rate.should_receive(:find).with(:all, {
|
||||||
|
:conditions => ["user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?",
|
||||||
|
@user.id,
|
||||||
|
@project.id,
|
||||||
|
@date
|
||||||
|
],
|
||||||
|
:order => 'date_in_effect DESC'
|
||||||
|
}).and_return(rates)
|
||||||
|
Rate.for(@user, @project, @date).should eql(rate1.amount)
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user