@@ -40,7 +40,11 @@ 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
|
||||
raise Rate::InvalidParameterException.new("user must be a User instance") unless user.is_a?(User)
|
||||
if Object.const_defined? 'Group' # 0.8.x compatibility
|
||||
raise Rate::InvalidParameterException.new("user must be a Principal instance") unless user.is_a?(Principal)
|
||||
else
|
||||
raise Rate::InvalidParameterException.new("user must be a User instance") unless user.is_a?(User)
|
||||
end
|
||||
raise Rate::InvalidParameterException.new("project must be a Project instance") unless project.nil? || project.is_a?(Project)
|
||||
Rate.check_date_string(date)
|
||||
|
||||
|
||||
@@ -28,7 +28,13 @@ class RateProjectHook < Redmine::Hook::ViewListener
|
||||
|
||||
return '' unless (User.current.allowed_to?(:view_rate, project) || User.current.admin?)
|
||||
|
||||
rate = Rate.for(member.user, project)
|
||||
if Object.const_defined? 'Group' # 0.8.x compatibility
|
||||
# Groups cannot have a rate
|
||||
return content_tag(:td,'') if member.principal.is_a? Group
|
||||
rate = Rate.for(member.principal, project)
|
||||
else
|
||||
rate = Rate.for(member.user, project)
|
||||
end
|
||||
|
||||
content = ''
|
||||
|
||||
|
||||
@@ -222,7 +222,7 @@ describe Rate, 'for' do
|
||||
Rate.should_not_receive(:for_user_project_and_date)
|
||||
lambda {
|
||||
Rate.for(object)
|
||||
}.should raise_error(Rate::InvalidParameterException, "user must be a User instance")
|
||||
}.should raise_error(Rate::InvalidParameterException, "user must be a Principal instance")
|
||||
end
|
||||
|
||||
it 'with an invalid project should raise an InvalidParameterException' do
|
||||
|
||||
Reference in New Issue
Block a user