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.rbindex 6a073197afb..d84e8b02d85 100644--- a/app/models/stat.rb+++ b/app/models/stat.rb@@ -51,7 +51,7 @@ class Statenddef self.calculate(stats)- stats.map { |stat| stat.calculate }.reduce(Hash.new, :merge)+ stats.map { |stat| stat.calculate }.reduce({}) { |memo, result| memo.deep_merge(result) }enddef self.core_statsdiff --git a/spec/models/stat_spec.rb b/spec/models/stat_spec.rbindex 277759278b7..e3b18e2fc74 100644--- a/spec/models/stat_spec.rb+++ b/spec/models/stat_spec.rb@@ -45,5 +45,14 @@ RSpec.describe Stat doStat.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 } })+ endendend