From cb8d2bc6dfc6080e68f7da6988c85be87f14f6f0 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 22 Apr 2009 11:53:50 -0700 Subject: [PATCH] [#2279] Added TimeEntryActivity#billable_custom_field to lookup and return the configured CustomField for the Billing Status. --- lib/overhead_time_entry_activity_patch.rb | 15 +++++++++++--- ...overhead_time_entry_activity_patch_spec.rb | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/lib/overhead_time_entry_activity_patch.rb b/lib/overhead_time_entry_activity_patch.rb index 7a912f9..13e3732 100644 --- a/lib/overhead_time_entry_activity_patch.rb +++ b/lib/overhead_time_entry_activity_patch.rb @@ -13,14 +13,23 @@ module OverheadTimeEntryActivityPatch end module ClassMethods - + # Returns the CustomField used for tracking Billable activities + def billable_custom_field + if overhead_configured? + TimeEntryActivityCustomField.find_by_id(Setting['plugin_redmine_overhead']['custom_field']) + end + end + + def overhead_configured? + Setting['plugin_redmine_overhead'] && Setting['plugin_redmine_overhead']['custom_field'] + end end module InstanceMethods # Is the Activity Billable, based on it's custom data? def billable? if overhead_configured? - billable_field = TimeEntryActivityCustomField.find_by_id(Setting['plugin_redmine_overhead']['custom_field']) + billable_field = TimeEntryActivity.billable_custom_field return field_equals_the_configured_billable_field?(billable_field) else return false @@ -30,7 +39,7 @@ module OverheadTimeEntryActivityPatch private def overhead_configured? - Setting['plugin_redmine_overhead'] && Setting['plugin_redmine_overhead']['custom_field'] + TimeEntryActivity.overhead_configured? end # Checks if the field's value equals the configured billable diff --git a/spec/lib/overhead_time_entry_activity_patch_spec.rb b/spec/lib/overhead_time_entry_activity_patch_spec.rb index 9fa64ea..2e9bdef 100644 --- a/spec/lib/overhead_time_entry_activity_patch_spec.rb +++ b/spec/lib/overhead_time_entry_activity_patch_spec.rb @@ -75,3 +75,23 @@ describe TimeEntryActivity, 'billable?' do end end + + +describe TimeEntryActivity, '#billable_custom_field' do + describe 'with overhead not configured' do + it 'should return nil' do + TimeEntryActivity.should_receive(:overhead_configured?).and_return(false) + TimeEntryActivity.billable_custom_field.should be_nil + end + end + + describe 'with overhead configured' do + it 'should return the custom field used to track Billable' do + TimeEntryActivity.should_receive(:overhead_configured?).and_return(true) + custom_field = mock_model(TimeEntryActivityCustomField) + TimeEntryActivityCustomField.should_receive(:find_by_id).and_return(custom_field) + + TimeEntryActivity.billable_custom_field.should eql(custom_field) + end + end +end