From e1278bcb69dad9a96272d235602b54c0562f02d7 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 16 Jan 2009 14:42:33 -0800 Subject: [PATCH] Patched UsersHelper#user_settings_tabs to add a new Rates tab * Wrapped UsersHelper#user_settings_tabs with an alias_method_chain * Added the new Rate element to the return of user_settings_tabs * Added RSpecs to confirm the change works without breaking * Added a partial view for users/rates which will be used by Redmine when it renders the user edit panel #1913 --- app/views/users/_rates.html.erb | 1 + init.rb | 2 ++ lang/en.yml | 2 +- lib/rate_users_helper_patch.rb | 24 +++++++++++++++ spec/lib/rate_users_helper_patch_spec.rb | 38 ++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/views/users/_rates.html.erb create mode 100644 lib/rate_users_helper_patch.rb create mode 100644 spec/lib/rate_users_helper_patch_spec.rb diff --git a/app/views/users/_rates.html.erb b/app/views/users/_rates.html.erb new file mode 100644 index 0000000..98293d4 --- /dev/null +++ b/app/views/users/_rates.html.erb @@ -0,0 +1 @@ +

Hello Rates

\ No newline at end of file diff --git a/init.rb b/init.rb index 4af2d5c..a7e0a75 100644 --- a/init.rb +++ b/init.rb @@ -1,5 +1,7 @@ require 'redmine' +require 'rate_users_helper_patch' + Redmine::Plugin.register :redmine_rate do name 'Rate Plugin' author 'Eric Davis' diff --git a/lang/en.yml b/lang/en.yml index e338591..0852e39 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -1,2 +1,2 @@ # English strings go here -my_label: "My label" +rate_label_rates: Rates diff --git a/lib/rate_users_helper_patch.rb b/lib/rate_users_helper_patch.rb new file mode 100644 index 0000000..3edcb94 --- /dev/null +++ b/lib/rate_users_helper_patch.rb @@ -0,0 +1,24 @@ +require_dependency 'users_helper' + +module RateUsersHelperPatch + def self.included(base) # :nodoc: + base.send(:include, InstanceMethods) + + base.class_eval do + alias_method_chain :user_settings_tabs, :rate_tab + end + end + + module InstanceMethods + # Adds a rates tab to the user administration page + def user_settings_tabs_with_rate_tab + tabs = user_settings_tabs_without_rate_tab + tabs << { :name => 'rates', :partial => 'users/rates', :label => :rate_label_rates} + return tabs + end + + end +end + +UsersHelper.send(:include, RateUsersHelperPatch) + diff --git a/spec/lib/rate_users_helper_patch_spec.rb b/spec/lib/rate_users_helper_patch_spec.rb new file mode 100644 index 0000000..14703d4 --- /dev/null +++ b/spec/lib/rate_users_helper_patch_spec.rb @@ -0,0 +1,38 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +class UsersHelperWrapper + include UsersHelper +end + +describe UsersHelper, 'user_settings' do + it 'should return 3 tabs' do + helper = UsersHelperWrapper.new + helper.user_settings_tabs.should have(3).things + + end + + it 'should include a rate tab at the end' do + helper = UsersHelperWrapper.new + rate_tab = helper.user_settings_tabs[-1] + rate_tab.should_not be_nil + end + + describe 'rate tab' do + before(:each) do + helper = UsersHelperWrapper.new + @rate_tab = helper.user_settings_tabs[-1] + end + + it 'should have the name of "rates"' do + @rate_tab[:name].should eql('rates') + end + + it 'should use the rates partial' do + @rate_tab[:partial].should eql('users/rates') + end + + it 'should use the i18n rates label' do + @rate_tab[:label].should eql(:rate_label_rates) + end + end +end