FIX: Support exporting reports which reference topics (#9957)

FIX: Support exporting reports which reference topics (#9957)

diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb
index 9485fc2..7d9b00d 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -231,6 +231,9 @@ module Jobs
         if label[:type] == :user
           titles[label[:properties][:username]] = label[:title]
           header << label[:properties][:username]
+        elsif label[:type] == :topic
+          titles[label[:properties][:id]] = label[:title]
+          header << label[:properties][:id]
         else
           titles[label[:property]] = label[:title]
           header << label[:property]
diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb
index 9182f9f..a29bae2 100644
--- a/spec/jobs/export_csv_file_spec.rb
+++ b/spec/jobs/export_csv_file_spec.rb
@@ -152,6 +152,20 @@ describe Jobs::ExportCsvFile do
       expect(report.second).to contain_exactly(user.username, "Earth", "2010-01-01 00:00:00 UTC")
     end
 
+    it 'works with topic reports' do
+      freeze_time DateTime.parse('2010-01-01 6:00')
+
+      exporter.extra['name'] = 'top_referred_topics'
+      post1 = Fabricate(:post)
+      post2 = Fabricate(:post)
+      IncomingLink.add(host: "a.com", referer: "http://twitter.com", post_id: post1.id, ip_address: '1.1.1.1')
+
+      report = exporter.report_export.to_a
+
+      expect(report.first).to contain_exactly("Topic", "Clicks")
+      expect(report.second).to contain_exactly(post1.topic.id.to_s, "1")
+    end
+
     it 'works with stacked_chart reports' do
       ApplicationRequest.create!(date: '2010-01-01', req_type: 'page_view_logged_in', count: 1)
       ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_logged_in', count: 2)

GitHub sha: 3106f859

1 Like

This commit appears in #9957 which was approved by eviltrout. It was merged by davidtaylorhq.