From 7fe913713adc8148ceac5740a8012c6f8be26896 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 8 Feb 2023 17:18:08 +1100 Subject: [PATCH] Use same parameters for report job as for original The Enterprise Fee Summary report modified the `params` object. So when we pass the same `params` a second time to the report class it doesn't find the same values. In some cases that would lead to a server error. The next commit implements a better solution though. --- lib/reporting/reports/enterprise_fee_summary/base.rb | 3 ++- .../enterprise_fee_summary_report_spec.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/reporting/reports/enterprise_fee_summary/base.rb b/lib/reporting/reports/enterprise_fee_summary/base.rb index 837c84df7d..ccbef3d323 100644 --- a/lib/reporting/reports/enterprise_fee_summary/base.rb +++ b/lib/reporting/reports/enterprise_fee_summary/base.rb @@ -8,7 +8,8 @@ module Reporting def initialize(user, params = {}, render: false) super(user, params, render: render) - p = params[:q] + # Clone hash before modifying it: + p = params[:q].clone if p.present? p['start_at'] = p.delete('completed_at_gt') p['end_at'] = p.delete('completed_at_lt') diff --git a/spec/lib/reports/enterprise_fee_summary/enterprise_fee_summary_report_spec.rb b/spec/lib/reports/enterprise_fee_summary/enterprise_fee_summary_report_spec.rb index 6ea086c7dd..f9ce422d39 100644 --- a/spec/lib/reports/enterprise_fee_summary/enterprise_fee_summary_report_spec.rb +++ b/spec/lib/reports/enterprise_fee_summary/enterprise_fee_summary_report_spec.rb @@ -99,6 +99,12 @@ describe Reporting::Reports::EnterpriseFeeSummary::Base do let!(:second_customer_order) { prepare_order(customer: customer) } let!(:other_customer_order) { prepare_order(customer: another_customer) } + it "doesn't delete params" do + params = ActionController::Parameters.new("completed_at_gt" => "2023-02-08+00:00") + described_class.new(current_user, params) + expect(params["completed_at_gt"]).to eq "2023-02-08+00:00" + end + it "groups and sorts entries correctly" do totals = subject.query_result