diff --git a/config/locales/en.yml b/config/locales/en.yml index ea5ed5b..324630d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,3 +4,5 @@ en: overhead_field_overhead_value: Overhead Value overhead_field_billable: Billable overhead_budget_spent: Overhead Spent + overhead_billable_time: Billable time + overhead_overhead_time: Overhead time \ No newline at end of file diff --git a/init.rb b/init.rb index c791cb2..50078f9 100644 --- a/init.rb +++ b/init.rb @@ -13,8 +13,9 @@ Dispatcher.to_prepare do TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch) end -require 'overhead_timesheet_hook' require 'overhead_budget_hook' +require 'overhead_issue_hook' +require 'overhead_timesheet_hook' Redmine::Plugin.register :redmine_overhead do name 'Overhead plugin' diff --git a/lib/overhead_issue_hook.rb b/lib/overhead_issue_hook.rb new file mode 100644 index 0000000..217d1fc --- /dev/null +++ b/lib/overhead_issue_hook.rb @@ -0,0 +1,16 @@ +class OverheadIssueHook < Redmine::Hook::ViewListener + def view_issues_show_details_bottom(context={}) + if context[:project].module_enabled?('budget_module') + billable_label = content_tag(:td, + content_tag(:strong, l(:overhead_billable_time)+":"), + :class => 'billable-hours') + billable_spent = content_tag(:td, l_hours(context[:issue].billable_time_spent)) + + return content_tag(:tr, + billable_label + billable_spent, + :class => 'overhead-plugin') + else + return '' + end + end +end diff --git a/spec/lib/overhead_issue_hook_spec.rb b/spec/lib/overhead_issue_hook_spec.rb new file mode 100644 index 0000000..284d4ec --- /dev/null +++ b/spec/lib/overhead_issue_hook_spec.rb @@ -0,0 +1,55 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +# Hack to make RSpec play nicely with call_hook's default contexts +def stub_view_to_use_controller_instance + self.stub!(:controller).and_return(@controller) +end + +describe OverheadIssueHook, "#view_issues_show_details_bottom with the budget disabled", :type => :view do + include Redmine::Hook::Helper + + before(:each) do + stub_view_to_use_controller_instance + end + + it 'should return nothing' do + project = mock_model(Project) + project.should_receive(:module_enabled?).at_least(:once).with('budget_module').and_return(false) + + context = { + :project => project, + :issue => mock_model(Issue, :project => project, :deliverable => nil) + } + + call_hook(:view_issues_show_details_bottom, context).strip.should eql('') + end +end + +describe OverheadIssueHook, "#view_issues_show_details_bottom with the budget disabled", :type => :view do + include Redmine::Hook::Helper + + before(:each) do + stub_view_to_use_controller_instance + @project = mock_model(Project) + @project.should_receive(:module_enabled?).at_least(:once).with('budget_module').and_return(true) + @issue = mock_model(Issue, :project => @project, :deliverable => nil, :billable_time_spent => nil) + + @context = { + :project => @project, + :issue => @issue + } + end + + it 'should be in a table row' do + call_hook(:view_issues_show_details_bottom, @context).should have_tag('tr.overhead-plugin') + end + + it 'should display a label for the billable time' do + call_hook(:view_issues_show_details_bottom, @context).should have_tag('td.billable-hours','Billable time:') + end + + it 'should display the number of billable hours' do + @issue.should_receive(:billable_time_spent).and_return(2.0) + call_hook(:view_issues_show_details_bottom, @context).should have_tag('td','2.00 hours') + end +end