diff --git a/app/models/team.rb b/app/models/team.rb index 5028a8a78..0bb18c223 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -661,6 +661,12 @@ def get_dashboard_exported_data(filters, dashboard_type) data end + def get_articles_exported_data(query) + fact_check_data = FactCheck.get_exported_data(query, self) + explainer_data = Explainer.get_exported_data(query, self).drop(1) # Remove the header, we don't need a second header + fact_check_data + explainer_data + end + # Platforms for which statistics are available (e.g., at least one media request) def statistics_platforms TiplineRequest.joins(:project_media).where('project_medias.team_id' => self.id).distinct.pluck(:platform) diff --git a/lib/list_export.rb b/lib/list_export.rb index 69f924502..3f6eb934a 100644 --- a/lib/list_export.rb +++ b/lib/list_export.rb @@ -1,5 +1,5 @@ class ListExport - TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard ] + TYPES = [:media, :feed, :fact_check, :explainer, :articles_dashboard, :tipline_dashboard, :articles] def initialize(type, query, team_id) @type = type @@ -21,6 +21,8 @@ def number_of_rows @team.filtered_fact_checks(@parsed_query).count when :explainer @team.filtered_explainers(@parsed_query).count + when :articles + @team.filtered_explainers(@parsed_query).count + @team.filtered_fact_checks(@parsed_query).count when :articles_dashboard, :tipline_dashboard 1 # Always maintain one row for dashboard data, but use different columns for export. end @@ -64,6 +66,8 @@ def export_data FactCheck.get_exported_data(@parsed_query, @team) when :explainer Explainer.get_exported_data(@parsed_query, @team) + when :articles + @team.get_articles_exported_data(@parsed_query) when :articles_dashboard, :tipline_dashboard @team.get_dashboard_exported_data(@parsed_query, @type) end diff --git a/test/lib/list_export_test.rb b/test/lib/list_export_test.rb index 3e26dd208..117f5c9b6 100644 --- a/test/lib/list_export_test.rb +++ b/test/lib/list_export_test.rb @@ -138,4 +138,20 @@ def teardown assert_equal 1, csv_content.size assert_equal 1, export.number_of_rows end + + test "should export articles CSV" do + t = create_team + create_explainer team: t + pm = create_project_media team: t + cd = create_claim_description project_media: pm + create_fact_check claim_description: cd + + export = ListExport.new(:articles, '{}', t.id) + csv_url = export.generate_csv_and_send_email(create_user) + response = Net::HTTP.get_response(URI(csv_url)) + assert_equal 200, response.code.to_i + csv_content = CSV.parse(response.body, headers: true) + assert_equal 2, csv_content.size + assert_equal 2, export.number_of_rows + end end