From 44ef5cdb0b598f6bf38395ffcec6f98c7e4f926b Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 19 Nov 2009 11:45:40 -0800 Subject: [PATCH] [#3306] Added the Billable column to the Timesheet plugin's CSV export. --- lib/overhead_timesheet_hook.rb | 14 +++++++ spec/lib/overhead_timesheet_hook_spec.rb | 48 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/lib/overhead_timesheet_hook.rb b/lib/overhead_timesheet_hook.rb index 5924d5b..9c44c3d 100644 --- a/lib/overhead_timesheet_hook.rb +++ b/lib/overhead_timesheet_hook.rb @@ -21,6 +21,20 @@ class OverheadTimesheetHook < Redmine::Hook::ViewListener end end + def plugin_timesheet_model_timesheet_csv_header(context={}) + context[:csv_data] << l(:overhead_field_billable) + end + + def plugin_timesheet_model_timesheet_time_entry_to_csv(context={}) + if context[:time_entry] + if context[:time_entry].billable? + context[:csv_data] << l(:overhead_field_billable) + else + context[:csv_data] << l(:overhead_field_overhead) + end + end + end + # Added a new field for filtering based on "billable?" def plugin_timesheet_views_timesheet_form(context={}) if context[:params] && diff --git a/spec/lib/overhead_timesheet_hook_spec.rb b/spec/lib/overhead_timesheet_hook_spec.rb index 07b1b9e..2076243 100644 --- a/spec/lib/overhead_timesheet_hook_spec.rb +++ b/spec/lib/overhead_timesheet_hook_spec.rb @@ -50,6 +50,54 @@ describe OverheadTimesheetHook, "#plugin_timesheet_views_timesheet_time_entry" d end end +describe OverheadTimesheetHook, "#plugin_timesheet_model_timesheet_csv_header" do + + def call_hook(context) + OverheadTimesheetHook.instance.plugin_timesheet_model_timesheet_csv_header(context) + end + + it 'should add a Billable field' do + @csv_data = [] + call_hook(:csv_data => @csv_data) + @csv_data.should have(1).item + @csv_data[0].should eql('Billable') + end +end + +describe OverheadTimesheetHook, "#plugin_timesheet_model_timesheet_time_entry_to_csv" do + + def call_hook(context) + OverheadTimesheetHook.instance.plugin_timesheet_model_timesheet_time_entry_to_csv(context) + end + + describe 'with no time entry' do + it 'should change nothing' do + @csv_data = [] + call_hook(:csv_data => @csv_data, :time_entry => nil) + @csv_data.should have(0).items + end + end + + describe 'with a billable time entry' do + it 'should add "Billable" to the csv_data' do + @csv_data = [] + call_hook(:csv_data => @csv_data, :time_entry => mock_model(TimeEntry, :billable? => true)) + @csv_data.should have(1).item + @csv_data[0].should eql('Billable') + end + end + + describe 'with a non-billable time entry' do + it 'should add "Overhead" to the csv_data' do + @csv_data = [] + call_hook(:csv_data => @csv_data, :time_entry => mock_model(TimeEntry, :billable? => false)) + @csv_data.should have(1).item + @csv_data[0].should eql('Overhead') + end + end + +end + describe OverheadTimesheetHook, "#plugin_timesheet_views_timesheet_form", :type => :view do include Redmine::Hook::Helper