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

This commit is contained in:
David Taylor 2020-06-01 18:23:58 +01:00 committed by GitHub
parent 7b9d207175
commit 3106f85983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -231,6 +231,9 @@ module Jobs
if label[:type] == :user if label[:type] == :user
titles[label[:properties][:username]] = label[:title] titles[label[:properties][:username]] = label[:title]
header << label[:properties][:username] header << label[:properties][:username]
elsif label[:type] == :topic
titles[label[:properties][:id]] = label[:title]
header << label[:properties][:id]
else else
titles[label[:property]] = label[:title] titles[label[:property]] = label[:title]
header << label[:property] header << label[:property]

View File

@ -152,6 +152,20 @@ describe Jobs::ExportCsvFile do
expect(report.second).to contain_exactly(user.username, "Earth", "2010-01-01 00:00:00 UTC") expect(report.second).to contain_exactly(user.username, "Earth", "2010-01-01 00:00:00 UTC")
end 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 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-01', req_type: 'page_view_logged_in', count: 1)
ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_logged_in', count: 2) ApplicationRequest.create!(date: '2010-01-02', req_type: 'page_view_logged_in', count: 2)