From 073dfe11773c56d8e241664523f93f28aa2be8bc Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 13 Oct 2010 11:32:32 -0700 Subject: [PATCH] [#4604] Add an admin panel for the rate caches --- app/controllers/rate_caches_controller.rb | 10 +++++ app/views/rate_caches/index.html.erb | 1 + assets/images/database_refresh.png | Bin 0 -> 770 bytes config/locales/en.yml | 2 + init.rb | 3 ++ .../hooks/view_layouts_base_html_head_hook.rb | 9 +++++ test/integration/admin_panel_test.rb | 26 ++++++++++++ test/test_helper.rb | 38 ++++++++++++++++++ 8 files changed, 89 insertions(+) create mode 100644 app/controllers/rate_caches_controller.rb create mode 100644 app/views/rate_caches/index.html.erb create mode 100644 assets/images/database_refresh.png create mode 100644 lib/redmine_rate/hooks/view_layouts_base_html_head_hook.rb create mode 100644 test/integration/admin_panel_test.rb diff --git a/app/controllers/rate_caches_controller.rb b/app/controllers/rate_caches_controller.rb new file mode 100644 index 0000000..316c991 --- /dev/null +++ b/app/controllers/rate_caches_controller.rb @@ -0,0 +1,10 @@ +class RateCachesController < ApplicationController + unloadable + + layout 'admin' + + before_filter :require_admin + + def index + end +end diff --git a/app/views/rate_caches/index.html.erb b/app/views/rate_caches/index.html.erb new file mode 100644 index 0000000..564eb6c --- /dev/null +++ b/app/views/rate_caches/index.html.erb @@ -0,0 +1 @@ +

<%= l(:text_rate_caches_panel) %>

diff --git a/assets/images/database_refresh.png b/assets/images/database_refresh.png new file mode 100644 index 0000000000000000000000000000000000000000..ff803be124ac5f1bd747490d2243f876eebdf5f6 GIT binary patch literal 770 zcmV+d1O5DoP)L1E-$)@F1-w)3&R|k zpe8{Z8<~c8GL+Q$?>DkG77MrB>ib*oIq``rr5B#_9^P}_=lwfJ$Ye4I1OislR|zeK zVbqYWCeYUSM0$zz3qqi|xmm|wBKZCO<8;X*Nm5-|Ss83L8wv^vz=$_CHjqpv5e|nD zi^V>Y?WWu9Ue99i`F!tXS!UrfyNRl*nP4!OdF<_2YxlP1Fme+XT27Rfmg0ZnbUKmN zQchLT0^98(MdnP?)6=lq?HnZ~C0I!=;+^~kYsqD3nhs6X;Vdi{?VA1UEzfmtU&~-q z7JwZi{gIM{t3{_E4UR1%)L*WJg$bH{MmVw30fE`e?I2IEj?l`hAghYH3 zt$W+>w6P28pTBBza%f!nsWhE`b~-<+1YOrT3B$cZ4>?gZ8b$I)lH1swJjJS$^EqF~ zm_fejtPITPCdn3|s^RUIA%3SpXiSi^{?8N`Oh=PY(SA|m3=BsGkWx0eT~QP?b~cPr zKhDrN8M!R7Nbz_a^b+|5(&_XcW=k#xvLap&a?YNRF|tvD>5s;|fF{5;0S zC%l5k;M1&07*qoM6N<$f 'rate_caches', :action => 'index'}, :caption => :text_rate_caches_panel end require 'redmine_rate/hooks/timesheet_hook_helper' @@ -44,3 +46,4 @@ require 'redmine_rate/hooks/plugin_timesheet_views_timesheet_group_header_hook' require 'redmine_rate/hooks/plugin_timesheet_views_timesheet_time_entry_hook' require 'redmine_rate/hooks/plugin_timesheet_views_timesheet_time_entry_sum_hook' require 'redmine_rate/hooks/plugin_timesheet_view_timesheets_report_header_tags_hook' +require 'redmine_rate/hooks/view_layouts_base_html_head_hook' diff --git a/lib/redmine_rate/hooks/view_layouts_base_html_head_hook.rb b/lib/redmine_rate/hooks/view_layouts_base_html_head_hook.rb new file mode 100644 index 0000000..8361aec --- /dev/null +++ b/lib/redmine_rate/hooks/view_layouts_base_html_head_hook.rb @@ -0,0 +1,9 @@ +module RedmineRate + module Hooks + class ViewLayoutsBaseHtmlHeadHook < Redmine::Hook::ViewListener + def view_layouts_base_html_head(context={}) + return content_tag(:style, "#admin-menu a.rate-caches { background-image: url('#{image_path('database_refresh.png', :plugin => 'redmine_rate')}'); }", :type => 'text/css') + end + end + end +end diff --git a/test/integration/admin_panel_test.rb b/test/integration/admin_panel_test.rb new file mode 100644 index 0000000..ea1c94f --- /dev/null +++ b/test/integration/admin_panel_test.rb @@ -0,0 +1,26 @@ +require 'test_helper' + +class AdminPanelTest < ActionController::IntegrationTest + def setup + @user = User.generate!(:admin => true, :password => 'rates', :password_confirmation => 'rates') + + login_as(@user.login, 'rates') + end + + context "Rate Caches admin panel" do + should "be listed in the main Admin section" do + click_link "Administration" + assert_response :success + + assert_select "#admin-menu" do + assert_select "a.rate-caches" + end + + end + + should "show the last run timestamp for the last caching run" + should "show the last run timestamp for the last cache clearing run" + should "have a button to force a caching run" + should "have a button to force a cache clearing run" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index bd1ed0c..9aa74bb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,3 +3,41 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../../test/test_helper # Ensure that we are using the temporary fixture path Engines::Testing.set_fixture_path + +require "webrat" + +Webrat.configure do |config| + config.mode = :rails +end + +module IntegrationTestHelper + def login_as(user="existing", password="existing") + visit "/login" + fill_in 'Login', :with => user + fill_in 'Password', :with => password + click_button 'login' + assert_response :success + assert User.current.logged? + end + + def logout + visit '/logout' + assert_response :success + assert !User.current.logged? + end + + def assert_forbidden + assert_response :forbidden + assert_template 'common/403' + end + + def assert_requires_login + assert_response :success + assert_template 'account/login' + end + +end + +class ActionController::IntegrationTest + include IntegrationTestHelper +end