Rate#for should handle invalid users. #1920

This commit is contained in:
Eric Davis committed 2009-01-16 16:40:50 -08:00
1 parent bab1fa7763
commit 08b267741b
2 files changed
+7 -4

No files matched your search

+1 -4
View File
@@ -26,6 +26,7 @@ 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)
return nil unless user.is_a?(User)
rate = self.for_user_project_and_date(user, project, date) rate = self.for_user_project_and_date(user, project, date)
return nil if rate.nil? return nil if rate.nil?
@@ -45,8 +46,4 @@ class Rate < ActiveRecord::Base
]) ])
end end
def self.for_user_and_date(user, date)
self.for_user_project_and_date(user, nil, date)
end
end end
+6
View File
@@ -190,6 +190,12 @@ describe Rate, 'for' do
Rate.for(@user).should eql(@rate.amount) Rate.for(@user).should eql(@rate.amount)
end end
end end
it 'with an invalid user should be nil' do
object = mock('random_object_with_id_attribute')
Rate.should_not_receive(:for_user_project_and_date)
Rate.for(object).should be_nil
end
end end
describe Rate, 'for_user_project_and_date (private)' do describe Rate, 'for_user_project_and_date (private)' do