A platform for community discussion. Free, open, simple.
DEV: there is no need anymore to wrap export methods into enumerators (#22567)
Andrei Prigorshnev54092833b981
diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rbindex 9897775dd21..e37e97e2002 100644--- a/app/jobs/regular/export_csv_file.rb+++ b/app/jobs/regular/export_csv_file.rb@@ -120,8 +120,6 @@ module Jobsenddef user_list_export- return enum_for(:user_list_export) unless block_given?-user_field_ids = UserField.pluck(:id)condition = {}@@ -148,8 +146,6 @@ module Jobsenddef staff_action_export- return enum_for(:staff_action_export) unless block_given?-staff_action_data =if @current_user.admin?UserHistory.only_staff_actions@@ -163,24 +159,18 @@ module Jobsenddef screened_email_export- return enum_for(:screened_email_export) unless block_given?-ScreenedEmail.find_each(order: :desc) do |screened_email|yield get_screened_email_fields(screened_email)endenddef screened_ip_export- return enum_for(:screened_ip_export) unless block_given?-ScreenedIpAddress.find_each(order: :desc) do |screened_ip|yield get_screened_ip_fields(screened_ip)endenddef screened_url_export- return enum_for(:screened_url_export) unless block_given?-ScreenedUrl.select("domain, sum(match_count) as match_count, max(last_match_at) as last_match_at, min(created_at) as created_at",@@ -191,8 +181,6 @@ module Jobsenddef report_export- return enum_for(:report_export) unless block_given?-# If dates are invalid consider then `nil`if @extra[:start_date].is_a?(String)@extra[:start_date] = begindiff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rbindex e395bddec54..621df2e512f 100644--- a/spec/jobs/export_csv_file_spec.rb+++ b/spec/jobs/export_csv_file_spec.rb@@ -81,9 +81,9 @@ RSpec.describe Jobs::ExportCsvFile doit "works with single-column reports" douser.user_visits.create!(visited_at: "2010-01-01", posts_read: 42)Fabricate(:user).user_visits.create!(visited_at: "2010-01-03", posts_read: 420)-exporter.extra["name"] = "dau_by_mau"- report = exporter.report_export.to_a++ report = export_reportexpect(report.first).to contain_exactly("Day", "Percent")expect(report.second).to contain_exactly("2010-01-01", "100.0")@@ -95,12 +95,13 @@ RSpec.describe Jobs::ExportCsvFile dogroup = Fabricate(:group)user1 = Fabricate(:user)- group_user = Fabricate(:group_user, group: group, user: user1)+ Fabricate(:group_user, group: group, user: user1)user1.user_visits.create!(visited_at: "2010-01-03", posts_read: 420)exporter.extra["name"] = "visits"exporter.extra["group"] = group.id- report = exporter.report_export.to_a++ report = export_reportexpect(report.length).to eq(2)expect(report.first).to contain_exactly("Day", "Count")@@ -110,9 +111,9 @@ RSpec.describe Jobs::ExportCsvFile doit "works with single-column reports with default label" douser.user_visits.create!(visited_at: "2010-01-01")Fabricate(:user).user_visits.create!(visited_at: "2010-01-03")-exporter.extra["name"] = "visits"- report = exporter.report_export.to_a++ report = export_reportexpect(report.first).to contain_exactly("Day", "Count")expect(report.second).to contain_exactly("2010-01-01", "1")@@ -126,9 +127,9 @@ RSpec.describe Jobs::ExportCsvFile doclient_ip: "1.1.1.1",created_at: "2010-01-01",)-exporter.extra["name"] = "staff_logins"- report = exporter.report_export.to_a++ report = export_reportexpect(report.first).to contain_exactly("User", "Location", "Login at")expect(report.second).to contain_exactly(user.username, "Earth", "2010-01-01 00:00:00 UTC")@@ -139,7 +140,7 @@ RSpec.describe Jobs::ExportCsvFile doexporter.extra["name"] = "top_referred_topics"post1 = Fabricate(:post)- post2 = Fabricate(:post)+ Fabricate(:post)IncomingLink.add(host: "a.com",referer: "http://twitter.com",@@ -147,7 +148,7 @@ RSpec.describe Jobs::ExportCsvFile doip_address: "1.1.1.1",)- report = exporter.report_export.to_a+ report = export_reportexpect(report.first).to contain_exactly("Topic", "Clicks")expect(report.second).to contain_exactly(post1.topic.id.to_s, "1")@@ -167,7 +168,8 @@ RSpec.describe Jobs::ExportCsvFile doApplicationRequest.create!(date: "2010-01-03", req_type: "page_view_crawler", count: 9)exporter.extra["name"] = "consolidated_page_views"- report = exporter.report_export.to_a++ report = export_reportexpect(report[0]).to contain_exactly("Day", "Logged in users", "Anonymous users", "Crawlers")expect(report[1]).to contain_exactly("2010-01-01", "1", "4", "7")@@ -193,15 +195,25 @@ RSpec.describe Jobs::ExportCsvFile doexporter.extra["name"] = "posts"exporter.extra["category"] = category.id- report = exporter.report_export.to_a++ report = export_report+expect(report[0]).to contain_exactly("Count", "Day")expect(report[1]).to contain_exactly("1", "2010-01-01")exporter.extra["include_subcategories"] = true- report = exporter.report_export.to_a++ report = export_report+expect(report[0]).to contain_exactly("Count", "Day")expect(report[1]).to contain_exactly("2", "2010-01-01")end++ def export_report+ report = []+ exporter.report_export { |entry| report << entry }+ report+ endendlet(:user_list_header) do@@ -244,7 +256,11 @@ RSpec.describe Jobs::ExportCsvFile do]end- let(:user_list_export) { Jobs::ExportCsvFile.new.user_list_export }+ let(:user_list_export) do+ exported_data = []+ Jobs::ExportCsvFile.new.user_list_export { |entry| exported_data << entry }+ exported_data+ enddef to_hash(row)Hash[*user_list_header.zip(row).flatten]