FIX: include default label when exporting reports

FIX: include default label when exporting reports

diff --git a/app/models/report.rb b/app/models/report.rb
index b16be16..783247f 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 8862906..79bdff7 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')

GitHub sha: 0603636c

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Can you review this commit @nbianca?

@techAPJ @nbianca is on vacation right now, but I think it looks OK :+1:

2 Likes