Skip to content

Commit 27a17da

Browse files
committed
FIX: Re-implement ReportGenerator.params_to_hash
1 parent e0bb6b3 commit 27a17da

File tree

2 files changed

+2
-18
lines changed

2 files changed

+2
-18
lines changed

lib/discourse_data_explorer/report_generator.rb

+1-17
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,10 @@ def self.generate_post(query_id, query_params, opts = {})
3535
build_report_post(query, table, attach_csv: opts[:attach_csv], result:)
3636
end
3737

38-
private
39-
4038
def self.params_to_hash(query_params)
4139
params = JSON.parse(query_params)
42-
params_hash = {}
43-
44-
if !params.blank?
45-
param_key, param_value = [], []
46-
params.flatten.each.with_index do |data, i|
47-
if i % 2 == 0
48-
param_key << data
49-
else
50-
param_value << data
51-
end
52-
end
53-
54-
params_hash = Hash[param_key.zip(param_value)]
55-
end
5640

57-
params_hash
41+
params.map { |p| p.is_a?(Hash) ? [p["key"], p["value"]] : p }.to_h
5842
end
5943

6044
def self.build_report_pms(query, table = "", targets = [], attach_csv: false, result: nil)

spec/report_generator_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256

257257
describe ".params_to_hash" do
258258
context "when passing nothing" do
259-
let(:query_params) { '[]' }
259+
let(:query_params) { "[]" }
260260

261261
it { expect(described_class.params_to_hash(query_params)).to eq({}) }
262262
end

0 commit comments

Comments
 (0)