From 620eaa262f3c668c959ad1b829bce8c092e43766 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Mon, 16 Aug 2010 09:39:27 -0700 Subject: [PATCH] [#4389] Add the Deliverable filter to the Time Entry report. --- app/models/deliverable.rb | 4 ++ init.rb | 1 + ...roller_timelog_available_criterias_hook.rb | 14 +++++ ...r_timelog_available_criterias_hook_test.rb | 55 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb create mode 100644 test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index 92d0386..c9cf09d 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -28,6 +28,10 @@ class Deliverable < ActiveRecord::Base '' end + def to_s + title + end + def to_underscore self.class.to_s.underscore end diff --git a/init.rb b/init.rb index 48faf6a..bf8aea4 100644 --- a/init.rb +++ b/init.rb @@ -85,3 +85,4 @@ require 'redmine_contracts/hooks/controller_issues_edit_before_save_hook' require 'redmine_contracts/hooks/view_issues_bulk_edit_details_bottom_hook' require 'redmine_contracts/hooks/controller_issues_bulk_edit_before_save_hook' require 'redmine_contracts/hooks/helper_issues_show_detail_after_setting_hook' +require 'redmine_contracts/hooks/controller_timelog_available_criterias_hook' diff --git a/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb b/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb new file mode 100644 index 0000000..99f35e5 --- /dev/null +++ b/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook.rb @@ -0,0 +1,14 @@ +module RedmineContracts + module Hooks + class ControllerTimelogAvailableCriteriasHook < Redmine::Hook::ViewListener + 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 + 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 new file mode 100644 index 0000000..ea4ae49 --- /dev/null +++ b/test/unit/lib/redmine_contracts/hooks/controller_timelog_available_criterias_hook_test.rb @@ -0,0 +1,55 @@ +require File.dirname(__FILE__) + '/../../../../test_helper' + +class RedmineContracts::Hooks::ControllerTimelogAvailableCriteriasTest < ActionController::TestCase + include Redmine::Hook::Helper + + def controller + @controller ||= ApplicationController.new + @controller.response ||= ActionController::TestResponse.new + @controller + end + + def request + @request ||= ActionController::TestRequest.new + end + + def hook(args={}) + call_hook :controller_timelog_available_criterias, args + end + + def context + @context ||= { + :available_criterias => {"existing" => {:label => 'existing'}} + } + end + + context "#controller_timelog_available_criterias" do + should "return an empty string" do + @response.body = hook(context) + assert @response.body.blank? + end + + context "Deliverables" do + should "add a deliverable_id to the available criterias" do + @response.body = hook(context) + assert context[:available_criterias]['deliverable_id'] + end + + should "add the deliverable sql to the available criterias" do + @response.body = hook(context) + assert "issues.deliverable_id", context[:available_criterias]['deliverable_id'][:sql] + end + + should "add the deliverable Class to the available criterias" do + @response.body = hook(context) + assert Deliverable, context[:available_criterias]['deliverable_id'][:klass] + end + + should "add the deliverable label to the available criterias" do + @response.body = hook(context) + assert :field_deliverable, context[:available_criterias]['deliverable_id'][:label] + end + end + + end +end