Instead of returning nil, which could get confused with No Rate, passing

incorrect objects to Rate#for will now throw a Rate::InvalidParameterException
back to the caller.

Normally you don't need to be this strict but this is a public API that will
be consumed by several third parties so we need to be very clear what happened.

  #1920
This commit is contained in:
Eric Davis
2009-01-16 16:53:00 -08:00
parent 94e8aad493
commit 7bca02b511
2 changed files with 12 additions and 6 deletions
+7 -3
View File
@@ -191,16 +191,20 @@ describe Rate, 'for' do
end
end
it 'with an invalid user should be nil' do
it 'with an invalid user should raise an InvalidParameterException' do
object = mock('random_object_with_id_attribute')
Rate.should_not_receive(:for_user_project_and_date)
Rate.for(object).should be_nil
lambda {
Rate.for(object)
}.should raise_error(Rate::InvalidParameterException, "user must be a User instance")
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
lambda {
Rate.for(@user, object)
}.should raise_error(Rate::InvalidParameterException, "project must be a Project instance")
end
end