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
This commit is contained in:
Eric Davis
2009-01-16 14:42:33 -08:00
parent 48d394704a
commit e1278bcb69
5 changed files with 66 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
<h1>Hello Rates</h1>
+2
View File
@@ -1,5 +1,7 @@
require 'redmine'
require 'rate_users_helper_patch'
Redmine::Plugin.register :redmine_rate do
name 'Rate Plugin'
author 'Eric Davis'
+1 -1
View File
@@ -1,2 +1,2 @@
# English strings go here
my_label: "My label"
rate_label_rates: Rates
+24
View File
@@ -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)
+38
View File
@@ -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