diff --git a/config/locales/en.yml b/config/locales/en.yml index 38a22ee..ea5ed5b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,3 +3,4 @@ en: overhead_field_billable_value: Billable Value overhead_field_overhead_value: Overhead Value overhead_field_billable: Billable + overhead_budget_spent: Overhead Spent diff --git a/lib/overhead_budget_hook.rb b/lib/overhead_budget_hook.rb index a9e2fe1..463f2ba 100644 --- a/lib/overhead_budget_hook.rb +++ b/lib/overhead_budget_hook.rb @@ -1,11 +1,20 @@ class OverheadBudgetHook < Redmine::Hook::ViewListener - + include DeliverablesHelper + def plugin_budget_view_deliverable_list_header(context={}) - return content_tag(:th, '') + return content_tag(:th, l(:overhead_budget_spent)) end def plugin_budget_view_deliverable_summary_row(context={}) - return content_tag(:td, '') + if context[:deliverable] + # Used by allowed_management? + @project = context[:deliverable].project + if allowed_management? + return content_tag(:td, number_to_currency(context[:deliverable].overhead_spent, :precision => 0)) + end + else + return content_tag(:td, '') + end end def plugin_budget_view_deliverable_details_row(context={}) diff --git a/spec/lib/overhead_budget_hook_spec.rb b/spec/lib/overhead_budget_hook_spec.rb index cf0ee6c..cd0f8bb 100644 --- a/spec/lib/overhead_budget_hook_spec.rb +++ b/spec/lib/overhead_budget_hook_spec.rb @@ -12,7 +12,9 @@ describe OverheadBudgetHook, "#plugin_budget_view_deliverable_list_header", :typ stub_view_to_use_controller_instance end - + it 'should return a table header with "Overhead Spent"' do + call_hook(:plugin_budget_view_deliverable_list_header, {}).should have_tag('th','Overhead Spent') + end end describe OverheadBudgetHook, "#plugin_budget_view_deliverable_summary_row", :type => :view do @@ -22,7 +24,39 @@ describe OverheadBudgetHook, "#plugin_budget_view_deliverable_summary_row", :typ stub_view_to_use_controller_instance end + it 'should return a table cell to align the table' do + call_hook(:plugin_budget_view_deliverable_summary_row, {}).should have_tag('td') + end + describe 'for users with management rights' do + before(:each) do + @deliverable = Deliverable.new + OverheadBudgetHook.instance.stub!(:allowed_management?).and_return(true) + end + + it 'should display the amount of overhead that has been spent' do + @deliverable.should_receive(:overhead_spent).and_return(100) + call_hook(:plugin_budget_view_deliverable_summary_row, {:deliverable => @deliverable}).should match(/100/) + end + + it 'should display the amount as a currency' do + @deliverable.should_receive(:overhead_spent).and_return(100) + call_hook(:plugin_budget_view_deliverable_summary_row, {:deliverable => @deliverable}).should have_tag('td', '$100') + end + + it 'should round the amount to 0 decimal places' do + @deliverable.should_receive(:overhead_spent).and_return(105.99) + call_hook(:plugin_budget_view_deliverable_summary_row, {:deliverable => @deliverable}).should have_tag('td', '$106') + end + end + + describe 'for users with management rights' do + it 'should be an empty table cell' do + OverheadBudgetHook.instance.stub!(:allowed_management?).and_return(false) + deliverable = Deliverable.new + call_hook(:plugin_budget_view_deliverable_summary_row, {:deliverable => deliverable }).should have_tag('td','') + end + end end describe OverheadBudgetHook, "#plugin_budget_view_deliverable_details_row", :type => :view do