From 720da2c554cac21804d93c5f870d5f777ccd9df2 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 16 Aug 2010 09:54:09 -0700 Subject: [PATCH] [#4389] Added the Contract filter to the Time Entry report. --- app/models/contract.rb | 4 ++++ ...roller_timelog_available_criterias_hook.rb | 5 ++++ ...r_timelog_available_criterias_hook_test.rb | 24 ++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/models/contract.rb b/app/models/contract.rb index 537e3f3..0e65756 100644 --- a/app/models/contract.rb +++ b/app/models/contract.rb @@ -106,6 +106,10 @@ class Contract < ActiveRecord::Base end end + def to_s + name + end + if Rails.env.test? generator_for :name, :method => :next_name generator_for :executed => true diff --git a/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb b/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb index 99f35e5..ffcd271 100644 --- a/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb +++ b/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb @@ -7,6 +7,11 @@ module RedmineContracts :klass => Deliverable, :label => :field_deliverable } + context[:available_criterias]["contract_id"] = { + :sql => "(SELECT deliverable.contract_id FROM #{Deliverable.table_name} deliverable WHERE deliverable.id = issues.deliverable_id)", + :klass => Contract, + :label => :field_contract + } return '' end end diff --git a/test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb b/test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb index ea4ae49..641c415 100644 --- a/test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb +++ b/test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb @@ -50,6 +50,28 @@ class RedmineContracts::Hooks::ControllerTimelogAvailableCriteriasTest < ActionC assert :field_deliverable, context[:available_criterias]['deliverable_id'][:label] end end - + + context "Contracts" do + should "add a contract_id to the available criterias" do + @response.body = hook(context) + assert context[:available_criterias]['contract_id'] + end + + should "add the contact sql to the available criterias" do + @response.body = hook(context) + assert "issues.deliverable_id", context[:available_criterias]['contract_id'][:sql] + end + + should "add the deliverable Class to the available criterias" do + @response.body = hook(context) + assert Contract, context[:available_criterias]['contract_id'][:klass] + end + + should "add the deliverable label to the available criterias" do + @response.body = hook(context) + assert :field_contract, context[:available_criterias]['contract_id'][:label] + end + end + end end