Merge pull request #7879 from opf/fix/31667/project_id_group

[31667] Fix ambiguous reference to project_id when group/sort
pull/7892/head
Henriette Dinger 5 years ago committed by GitHub
commit 52484ae71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      app/models/queries/work_packages/columns/property_column.rb
  2. 32
      spec/models/query/results_spec.rb

@ -43,7 +43,7 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co
project: { project: {
association: 'project', association: 'project',
sortable: "name", sortable: "name",
groupable: 'project_id' groupable: "#{WorkPackage.table_name}.project_id"
}, },
subject: { subject: {
sortable: "#{WorkPackage.table_name}.subject" sortable: "#{WorkPackage.table_name}.subject"
@ -51,7 +51,7 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co
type: { type: {
association: 'type', association: 'type',
sortable: "position", sortable: "position",
groupable: 'type_id' groupable: "#{WorkPackage.table_name}.type_id"
}, },
parent: { parent: {
association: 'ancestors_relations', association: 'ancestors_relations',
@ -62,35 +62,35 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co
association: 'status', association: 'status',
sortable: "position", sortable: "position",
highlightable: true, highlightable: true,
groupable: 'status_id' groupable: "#{WorkPackage.table_name}.status_id"
}, },
priority: { priority: {
association: 'priority', association: 'priority',
sortable: "position", sortable: "position",
default_order: 'desc', default_order: 'desc',
highlightable: true, highlightable: true,
groupable: 'priority_id' groupable: "#{WorkPackage.table_name}.priority_id"
}, },
author: { author: {
association: 'author', association: 'author',
sortable: ["lastname", sortable: ["lastname",
"firstname", "firstname",
"id"], "id"],
groupable: 'author_id' groupable: "#{WorkPackage.table_name}.author_id"
}, },
assigned_to: { assigned_to: {
association: 'assigned_to', association: 'assigned_to',
sortable: ["lastname", sortable: ["lastname",
"firstname", "firstname",
"id"], "id"],
groupable: 'assigned_to_id' groupable: "#{WorkPackage.table_name}.assigned_to_id"
}, },
responsible: { responsible: {
association: 'responsible', association: 'responsible',
sortable: ["lastname", sortable: ["lastname",
"firstname", "firstname",
"id"], "id"],
groupable: 'responsible_id' groupable: "#{WorkPackage.table_name}.responsible_id"
}, },
updated_at: { updated_at: {
sortable: "#{WorkPackage.table_name}.updated_at", sortable: "#{WorkPackage.table_name}.updated_at",
@ -99,13 +99,13 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co
category: { category: {
association: 'category', association: 'category',
sortable: "name", sortable: "name",
groupable: 'category_id' groupable: "#{WorkPackage.table_name}.category_id"
}, },
fixed_version: { fixed_version: {
association: 'fixed_version', association: 'fixed_version',
sortable: ["name"], sortable: ["name"],
default_order: 'desc', default_order: 'desc',
groupable: 'fixed_version_id' groupable: "#{WorkPackage.table_name}.fixed_version_id"
}, },
start_date: { start_date: {
# Put empty start_dates in the far future rather than in the far past # Put empty start_dates in the far future rather than in the far past

@ -604,6 +604,38 @@ describe ::Query::Results, type: :model, with_mail: false do
end end
end end
context 'sorting by priority, grouping by project' do
let(:prio_low) { FactoryBot.create :issue_priority, position: 1 }
let(:prio_high) { FactoryBot.create :issue_priority, position: 0 }
let(:group_by) { 'project' }
before do
allow(User).to receive(:current).and_return(user_1)
work_package1.priority = prio_low
work_package2.priority = prio_high
work_package1.save(validate: false)
work_package2.save(validate: false)
end
it 'properly selects project_id (Regression #31667)' do
query.sort_criteria = [['priority', 'asc']]
expect(query_results.sorted_work_packages)
.to match [work_package1, work_package2]
query.sort_criteria = [['priority', 'desc']]
expect(query_results.sorted_work_packages)
.to match [work_package2, work_package1]
group_count = query_results.work_package_count_by_group
expect(group_count).to eq({ project_1 => 2 })
end
end
context 'sorting by author and responsible, grouping by assigned_to' do context 'sorting by author and responsible, grouping by assigned_to' do
let(:group_by) { 'assigned_to' } let(:group_by) { 'assigned_to' }
let(:sort_by) { [['author', 'asc'], ['responsible', 'desc']] } let(:sort_by) { [['author', 'asc'], ['responsible', 'desc']] }

Loading…
Cancel
Save