[#2279] Added TimeEntryActivity#billable_custom_field to lookup and return

the configured CustomField for the Billing Status.
This commit is contained in:
Eric Davis
2009-04-22 11:53:50 -07:00
parent 467c1259d8
commit cb8d2bc6df
2 changed files with 32 additions and 3 deletions

View File

@@ -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

View File

@@ -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