diff --git a/init.rb b/init.rb index 9d63c63..8940541 100644 --- a/init.rb +++ b/init.rb @@ -2,8 +2,10 @@ require 'redmine' # Patches to the Redmine core. require 'dispatcher' +require 'overhead_time_entry_patch' require 'overhead_time_entry_activity_patch' Dispatcher.to_prepare do + TimeEntry.send(:include, OverheadTimeEntryPatch) TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch) end diff --git a/lib/overhead_time_entry_patch.rb b/lib/overhead_time_entry_patch.rb new file mode 100644 index 0000000..1e5b12e --- /dev/null +++ b/lib/overhead_time_entry_patch.rb @@ -0,0 +1,11 @@ +require_dependency 'time_entry' + +module OverheadTimeEntryPatch + def self.included(base) + base.class_eval do + unloadable + delegate :billable?, :to => :activity + end + end +end + diff --git a/spec/lib/overhead_time_entry_patch_spec.rb b/spec/lib/overhead_time_entry_patch_spec.rb new file mode 100644 index 0000000..fc141b0 --- /dev/null +++ b/spec/lib/overhead_time_entry_patch_spec.rb @@ -0,0 +1,21 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe TimeEntry, 'billable?' do + before(:each) do + @time_entry = TimeEntry.new + end + + it 'should be true if the activity is considered billable' do + @time_entry.should_receive(:activity).and_return do + mock_model(TimeEntryActivity, :billable? => true) + end + @time_entry.billable?.should be_true + end + + it 'should be false if the activity is considered overhead' do + @time_entry.should_receive(:activity).and_return do + mock_model(TimeEntryActivity, :billable? => false) + end + @time_entry.billable?.should be_false + end +end