diff --git a/app/models/rate.rb b/app/models/rate.rb index 9db4aab..e1fe998 100644 --- a/app/models/rate.rb +++ b/app/models/rate.rb @@ -26,7 +26,10 @@ class Rate < ActiveRecord::Base # 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) + # Check input since it's a "public" API return nil unless user.is_a?(User) + return nil unless project.nil? || project.is_a?(Project) + rate = self.for_user_project_and_date(user, project, date) return nil if rate.nil? diff --git a/spec/models/rate_spec.rb b/spec/models/rate_spec.rb index 314a6a2..5868e57 100644 --- a/spec/models/rate_spec.rb +++ b/spec/models/rate_spec.rb @@ -196,6 +196,13 @@ describe Rate, 'for' do Rate.should_not_receive(:for_user_project_and_date) Rate.for(object).should be_nil end + + it 'with an invalid project should be nil' do + object = mock('random_object_with_id_attribute') + Rate.should_not_receive(:for_user_project_and_date) + Rate.for(@user, object).should be_nil + end + end describe Rate, 'for_user_project_and_date (private)' do