diff --git a/init.rb b/init.rb index 0530c55..19e673c 100644 --- a/init.rb +++ b/init.rb @@ -92,8 +92,12 @@ Dispatcher.to_prepare :redmine_contracts do Query.add_available_column(QueryColumn.new(:deliverable, :sortable => "#{Deliverable.table_name}.title", :groupable => 'deliverable')) end + # Hack in order to get the associated contract to be grouped by name + # * Proxy method Issue#contract_name + # * Naming Query column contract_name + # * Grouping by 'contracts.name' unless Query.available_columns.collect(&:name).include?(:contract_name) - Query.add_available_column(QueryColumn.new(:contract_name, :sortable => "#{Contract.table_name}.name", :groupable => 'contract_id')) + Query.add_available_column(QueryColumn.new(:contract_name, :sortable => "#{Contract.table_name}.name", :groupable => 'contracts.name')) end end diff --git a/lib/redmine_contracts/patches/issue_patch.rb b/lib/redmine_contracts/patches/issue_patch.rb index c2d0597..4df6003 100644 --- a/lib/redmine_contracts/patches/issue_patch.rb +++ b/lib/redmine_contracts/patches/issue_patch.rb @@ -10,7 +10,11 @@ module RedmineContracts belongs_to :deliverable delegate :title, :to => :deliverable, :prefix => true, :allow_nil => true - delegate :contract_name, :to => :deliverable, :allow_nil => true + delegate :contract, :to => :deliverable, :allow_nil => true + + def contract_name + contract.try(:name) + end end end diff --git a/test/integration/issue_filtering_test.rb b/test/integration/issue_filtering_test.rb index 395b8c3..7ec6513 100644 --- a/test/integration/issue_filtering_test.rb +++ b/test/integration/issue_filtering_test.rb @@ -62,7 +62,7 @@ class IssueFilteringTest < ActionController::IntegrationTest assert_select "span.count", "(1)" end assert_select "td", :text => Regexp.new(@contract.name) do - assert_select "span.count", "()" + assert_select "span.count", "(1)" end end