Implementing Rate#for's internal logic. #1920
This commit is contained in:
1 parent
0d9c7e50de
commit
b59c87b1f6
2 files changed
+43
-6
No files matched your search
@@ -26,5 +26,13 @@ class Rate < ActiveRecord::Base
|
|||||||
|
|
||||||
# API to find the Rate for a +user+ on a +project+ at a +date+
|
# API to find the Rate for a +user+ on a +project+ at a +date+
|
||||||
def self.for(user, project = nil, date = Date.today.to_s)
|
def self.for(user, project = nil, date = Date.today.to_s)
|
||||||
|
rates = Rate.find(:all,
|
||||||
|
:conditions => ["user_id IN (?) AND project_id IN (?) AND date_in_effect <= ?",
|
||||||
|
user.id,
|
||||||
|
project.id,
|
||||||
|
date
|
||||||
|
],
|
||||||
|
:order => 'date_in_effect DESC')
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -123,13 +123,13 @@ describe Rate, 'destroy' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe Rate, 'for' do
|
describe Rate, 'for' do
|
||||||
describe 'parameters' do
|
before(:each) do
|
||||||
before(:each) do
|
@user = mock_model(User)
|
||||||
@user = mock_model(User)
|
@project = mock_model(Project)
|
||||||
@project = mock_model(Project)
|
@date = '2009-01-01'
|
||||||
@date = '2009-01-01'
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
describe 'parameters' do
|
||||||
it 'should be passed user' do
|
it 'should be passed user' do
|
||||||
lambda {Rate.for}.should raise_error(ArgumentError)
|
lambda {Rate.for}.should raise_error(ArgumentError)
|
||||||
end
|
end
|
||||||
@@ -145,4 +145,33 @@ describe Rate, 'for' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'returns' do
|
||||||
|
it 'a decimal when there is a rate'
|
||||||
|
|
||||||
|
it 'a nil when there is no rate' do
|
||||||
|
Rate.for(@user, @project, @date).should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with a user, project, and date' do
|
||||||
|
it 'should find all the rates for a user on the project before the date' do
|
||||||
|
rate1 = mock_model(Rate)
|
||||||
|
rate2 = mock_model(Rate)
|
||||||
|
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)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should return the value of the most recent rate found'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user