From 0603636cea0a2c6e533f50c58651a6867d279e13 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 26 Jul 2019 12:57:13 +0530 Subject: [PATCH] FIX: include default label when exporting reports --- app/models/report.rb | 1 + spec/jobs/export_csv_file_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/models/report.rb b/app/models/report.rb index b16be1632ec..783247fb0f9 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -152,6 +152,7 @@ class Report report.average = opts[:average] if opts[:average] report.percent = opts[:percent] if opts[:percent] report.filters = opts[:filters] if opts[:filters] + report.labels = Report.default_labels report end diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb index 88629062bf4..79bdff73361 100644 --- a/spec/jobs/export_csv_file_spec.rb +++ b/spec/jobs/export_csv_file_spec.rb @@ -66,6 +66,18 @@ describe Jobs::ExportCsvFile do expect(report.third).to contain_exactly("2010-01-03", "50.0") end + it 'works with single-column reports with default label' do + user.user_visits.create!(visited_at: '2010-01-01') + Fabricate(:user).user_visits.create!(visited_at: '2010-01-03') + + exporter.instance_variable_get(:@extra)['name'] = 'visits' + report = exporter.report_export.to_a + + expect(report.first).to contain_exactly("Day", "Count") + expect(report.second).to contain_exactly("2010-01-01", "1") + expect(report.third).to contain_exactly("2010-01-03", "1") + end + it 'works with multi-columns reports' do DiscourseIpInfo.stubs(:get).with("1.1.1.1").returns(location: "Earth") user.user_auth_token_logs.create!(action: "login", client_ip: "1.1.1.1", created_at: '2010-01-01')