diff --git a/lib/redmine_budget/hooks/controller_timelog_available_criterias_hook.rb b/lib/redmine_budget/hooks/controller_timelog_available_criterias_hook.rb index 7986143..38cfda4 100644 --- a/lib/redmine_budget/hooks/controller_timelog_available_criterias_hook.rb +++ b/lib/redmine_budget/hooks/controller_timelog_available_criterias_hook.rb @@ -1,7 +1,13 @@ module RedmineBudget module Hooks class ControllerTimelogAvailableCriteriasHook < Redmine::Hook::ViewListener + # Adds the Deliverable as a filter to the Timelog Report def controller_timelog_available_criterias(context={}) + context[:available_criterias]["deliverable_id"] = { + :sql => "#{Issue.table_name}.deliverable_id", + :klass => Deliverable, + :label => :field_deliverable + } return '' end end diff --git a/spec/models/controller_timelog_available_criterias_hook_spec.rb b/spec/models/controller_timelog_available_criterias_hook_spec.rb index 8eef810..56238e8 100644 --- a/spec/models/controller_timelog_available_criterias_hook_spec.rb +++ b/spec/models/controller_timelog_available_criterias_hook_spec.rb @@ -12,8 +12,44 @@ def request @request ||= ActionController::TestRequest.new end -describe TimelogController, '#controller_timelog_available_criterias_hook', :type => :controller do - it 'should return an empty string' do - call_hook(:controller_timelog_available_criterias, {}).should be_blank - end +def run_hook + call_hook(:controller_timelog_available_criterias, {:available_criterias => @available_criterias}) +end + +describe TimelogController, '#controller_timelog_available_criterias_hook', :type => :controller do + before(:each) do + @available_criterias = { + 'project' => {:sql => 'project_id', :klass => Project, :label => :label_project} + } + end + + it "should always return an empty string" do + run_hook.should be_blank + end + + it "should add a new hash to the available_criterias" do + run_hook + + @available_criterias.should have(2).keys + @available_criterias.key?('deliverable_id').should be_true + end + + it "should set the :sql field to use the issue's deliverable_id" do + run_hook + + @available_criterias['deliverable_id'][:sql].should eql("issues.deliverable_id") + end + + it "should set the :klass field to Deliverable" do + run_hook + + @available_criterias['deliverable_id'][:klass].should eql(Deliverable) + end + + it "should set the :label field to :field_deliverable" do + run_hook + + @available_criterias['deliverable_id'][:label].should eql(:field_deliverable) + end + end