Skip to content

A platform for community discussion. Free, open, simple.

FIX: Stat type grouping (#40783)

Martin Brennandcecdff7d93f
diff --git a/app/models/stat.rb b/app/models/stat.rb
index 6a073197afb..d84e8b02d85 100644
--- a/app/models/stat.rb
+++ b/app/models/stat.rb
@@ -51,7 +51,7 @@ class Stat
end
def self.calculate(stats)
- stats.map { |stat| stat.calculate }.reduce(Hash.new, :merge)
+ stats.map { |stat| stat.calculate }.reduce({}) { |memo, result| memo.deep_merge(result) }
end
def self.core_stats
diff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rb
index 277759278b7..e3b18e2fc74 100644
--- a/spec/models/stat_spec.rb
+++ b/spec/models/stat_spec.rb
@@ -45,5 +45,14 @@ RSpec.describe Stat do
Stat.new("test", stat_type: :test) { { "7_days" => 1, "30_days" => 10, "count" => 100 } }
expect(stat.calculate).to eq({ test: { test_7_days: 1, test_30_days: 10, test_count: 100 } })
end
+
+ it "merges multiple stats with the same stat type" do
+ stats = [
+ Stat.new("boards", stat_type: :kanban) { { count: 1 } },
+ Stat.new("cards", stat_type: :kanban) { { count: 2 } },
+ ]
+
+ expect(Stat.send(:calculate, stats)).to eq({ kanban: { boards_count: 1, cards_count: 2 } })
+ end
end
end