From 7f7b400f15a9f78d401f3e97477fe5b743319c7e Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 2 Nov 2009 18:30:17 -0800 Subject: [PATCH] [#3180 #3266] Compatibility fix for the Groups feature. --- app/models/rate.rb | 6 +++++- lib/rate_project_hook.rb | 8 +++++++- spec/models/rate_spec.rb | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/models/rate.rb b/app/models/rate.rb index 9343e65..2540200 100644 --- a/app/models/rate.rb +++ b/app/models/rate.rb @@ -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) diff --git a/lib/rate_project_hook.rb b/lib/rate_project_hook.rb index 0cf098a..0819d1f 100644 --- a/lib/rate_project_hook.rb +++ b/lib/rate_project_hook.rb @@ -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 = '' diff --git a/spec/models/rate_spec.rb b/spec/models/rate_spec.rb index 570b050..d068ca9 100644 --- a/spec/models/rate_spec.rb +++ b/spec/models/rate_spec.rb @@ -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