fix lost grouping in exports; added regression test

pull/4859/head
Markus Kahl 8 years ago
parent 8345d178f6
commit 0e54c5fcf6
  1. 8
      app/helpers/queries_helper.rb
  2. 29
      spec/features/work_packages/export_spec.rb

@ -46,7 +46,7 @@ module QueriesHelper
# Retrieve query from session or build a new query
def retrieve_query
if !params[:query_id].blank?
if params[:query_id].present?
cond = 'project_id IS NULL'
cond << " OR project_id = #{@project.id}" if @project
@query = Query.where(cond).find(params[:query_id])
@ -67,7 +67,7 @@ module QueriesHelper
end
end
@query.group_by = params[:group_by]
@query.group_by = group_by_from_params params
@query.display_sums = params[:display_sums].present? && params[:display_sums] == 'true'
@query.column_names = column_names_from_params params
session[:query] = { project_id: @query.project_id, filters: @query.filters, group_by: @query.group_by, display_sums: @query.display_sums, column_names: @query.column_names }
@ -115,6 +115,10 @@ module QueriesHelper
module_function
def group_by_from_params(params)
params[:group_by] || params[:groupBy] || params[:g]
end
def fields_from_params(query, params)
fix_field_array(query, params[:fields] || params[:f]).compact
end

@ -33,12 +33,13 @@ describe 'work package export', type: :feature do
let(:project) { FactoryGirl.create :project_with_types, types: [type_a, type_b] }
let(:current_user) { FactoryGirl.create :admin }
let(:type_a) { FactoryGirl.create :type }
let(:type_b) { FactoryGirl.create :type }
let(:type_a) { FactoryGirl.create :type, name: "Type A" }
let(:type_b) { FactoryGirl.create :type, name: "Type B" }
let(:wp_1) { FactoryGirl.create :work_package, project: project, done_ratio: 25, type: type_a }
let(:wp_2) { FactoryGirl.create :work_package, project: project, done_ratio: 0, type: type_a }
let(:wp_3) { FactoryGirl.create :work_package, project: project, done_ratio: 0, type: type_b }
let(:wp_4) { FactoryGirl.create :work_package, project: project, done_ratio: 0, type: type_a }
let(:work_packages_page) { WorkPackagesPage.new(project) }
@ -46,6 +47,7 @@ describe 'work package export', type: :feature do
wp_1
wp_2
wp_3
wp_4
allow(User).to receive(:current).and_return current_user
end
@ -82,6 +84,29 @@ describe 'work package export', type: :feature do
expect(page).to have_text(wp_1.description)
expect(page).to have_text(wp_2.description)
expect(page).to have_text(wp_3.description)
expect(page).to have_text(wp_4.description)
# results are ordered by ID (desc) and not grouped by type
expect(page.text.scan(/Type (A|B)/).flatten).to eq %w(A B A A)
end
it 'shows all work packages grouped by ', js: true do
work_packages_page.ensure_loaded
work_packages_page.open_settings!
click_on 'Group by ...'
select 'Type', from: 'selected_columns_new'
click_on 'Apply'
export!
expect(page).to have_text(wp_1.description)
expect(page).to have_text(wp_2.description)
expect(page).to have_text(wp_3.description)
expect(page).to have_text(wp_4.description)
# grouped by type
expect(page.text.scan(/Type (A|B)/).flatten).to eq %w(A A A B)
end
it 'shows only the work package with the right progress if filtered this way', js: true do

Loading…
Cancel
Save