From 3e499faa7c77f893da19064c71a5352bb6a145f9 Mon Sep 17 00:00:00 2001 From: Kristina Lim Date: Fri, 14 Dec 2018 20:02:20 +1100 Subject: [PATCH] Do not use ReportData::EnterpriseFeeTypeTotals --- .../renderers/csv_renderer.rb | 2 +- .../renderers/html_renderer.rb | 2 +- .../report_data/enterprise_fee_type_totals.rb | 17 ------------ .../enterprise_fee_summary/report_service.rb | 5 ++-- .../renderers/csv_renderer_spec.rb | 14 +++++----- .../renderers/html_renderer_spec.rb | 14 +++++----- .../report_service_spec.rb | 26 +++++++++---------- 7 files changed, 29 insertions(+), 51 deletions(-) delete mode 100644 engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_totals.rb diff --git a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb index 32ab1188f5..c4c8450485 100644 --- a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb +++ b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer.rb @@ -11,7 +11,7 @@ module OrderManagement CSV.generate do |csv| render_header(csv) - report_data.enterprise_fee_type_totals.list.each do |data| + report_data.list.each do |data| render_data_row(csv, data) end end diff --git a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb index beace472ee..23ed8f26ba 100644 --- a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb +++ b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer.rb @@ -15,7 +15,7 @@ module OrderManagement end def data_rows - report_data.enterprise_fee_type_totals.list.map do |data| + report_data.list.map do |data| data_row_attributes.map do |attribute| data.public_send(attribute) end diff --git a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_totals.rb b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_totals.rb deleted file mode 100644 index dcc54ccf29..0000000000 --- a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_totals.rb +++ /dev/null @@ -1,17 +0,0 @@ -module OrderManagement - module Reports - module EnterpriseFeeSummary - module ReportData - class EnterpriseFeeTypeTotals < ::Reports::ReportData::Base - attr_accessor :list - - def initialize(*args) - @list = [] - - super(*args) - end - end - end - end - end -end diff --git a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_service.rb b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_service.rb index c40cffd308..b0ddc1c507 100644 --- a/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_service.rb +++ b/engines/order_management/lib/order_management/reports/enterprise_fee_summary/report_service.rb @@ -1,6 +1,5 @@ require "order_management/reports/enterprise_fee_summary/scope" require "order_management/reports/enterprise_fee_summary/enterprise_fee_type_total_summarizer" -require "order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_totals" require "order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total" module OrderManagement @@ -18,8 +17,8 @@ module OrderManagement Scope.new.apply_filters(permission_filters).apply_filters(parameters).result end - def enterprise_fee_type_totals - ReportData::EnterpriseFeeTypeTotals.new(list: enterprise_fee_type_total_list.sort) + def list + enterprise_fee_type_total_list.sort end private diff --git a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb index 13823d61b2..c12aa844bb 100644 --- a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb +++ b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/csv_renderer_spec.rb @@ -23,9 +23,8 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::CsvRenderer end let!(:enterprise_fee_type_totals) do - instance = report_klass::ReportData::EnterpriseFeeTypeTotals.new - instance.tap do |totals| - totals.list << report_klass::ReportData::EnterpriseFeeTypeTotal.new( + [ + report_klass::ReportData::EnterpriseFeeTypeTotal.new( fee_type: "Fee Type A", enterprise_name: "Enterprise A", fee_name: "Fee A", @@ -34,9 +33,8 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::CsvRenderer fee_calculated_on_transfer_through_name: "Transfer Enterprise A", tax_category_name: "Tax Category A", total_amount: "1.00" - ) - - totals.list << report_klass::ReportData::EnterpriseFeeTypeTotal.new( + ), + report_klass::ReportData::EnterpriseFeeTypeTotal.new( fee_type: "Fee Type B", enterprise_name: "Enterprise B", fee_name: "Fee C", @@ -46,13 +44,13 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::CsvRenderer tax_category_name: "Tax Category G", total_amount: "2.00" ) - end + ] end let(:current_user) { nil } before do - allow(service).to receive(:enterprise_fee_type_totals) { enterprise_fee_type_totals } + allow(service).to receive(:list) { enterprise_fee_type_totals } end it "generates CSV header" do diff --git a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer_spec.rb b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer_spec.rb index 3cc30f6abb..733b3dec74 100644 --- a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer_spec.rb +++ b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/renderers/html_renderer_spec.rb @@ -15,9 +15,8 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::HtmlRenderer let!(:renderer) { described_class.new(service) } let!(:enterprise_fee_type_totals) do - instance = report_klass::ReportData::EnterpriseFeeTypeTotals.new - instance.tap do |totals| - totals.list << report_klass::ReportData::EnterpriseFeeTypeTotal.new( + [ + report_klass::ReportData::EnterpriseFeeTypeTotal.new( fee_type: "Fee Type A", enterprise_name: "Enterprise A", fee_name: "Fee A", @@ -26,9 +25,8 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::HtmlRenderer fee_calculated_on_transfer_through_name: "Transfer Enterprise A", tax_category_name: "Tax Category A", total_amount: "1.00" - ) - - totals.list << report_klass::ReportData::EnterpriseFeeTypeTotal.new( + ), + report_klass::ReportData::EnterpriseFeeTypeTotal.new( fee_type: "Fee Type B", enterprise_name: "Enterprise B", fee_name: "Fee C", @@ -38,13 +36,13 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::Renderers::HtmlRenderer tax_category_name: "Tax Category G", total_amount: "2.00" ) - end + ] end let(:current_user) { nil } before do - allow(service).to receive(:enterprise_fee_type_totals) { enterprise_fee_type_totals } + allow(service).to receive(:list) { enterprise_fee_type_totals } end it "generates header values" do diff --git a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/report_service_spec.rb b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/report_service_spec.rb index 8b3d522e34..9d196bbb11 100644 --- a/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/report_service_spec.rb +++ b/engines/order_management/spec/lib/order_management/reports/enterprise_fee_summary/report_service_spec.rb @@ -89,9 +89,9 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:service) { described_class.new(permissions, parameters) } it "groups and sorts entries correctly" do - totals = service.enterprise_fee_type_totals + totals = service.list - expect(totals.list.length).to eq(16) + expect(totals.length).to eq(16) # Data is sorted by the following, in order: # * fee_type @@ -139,7 +139,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do ] expected_result.each_with_index do |expected_attributes, row_index| - expect_total_attributes(totals.list[row_index], expected_attributes) + expect_total_attributes(totals[row_index], expected_attributes) end end end @@ -171,7 +171,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let!(:current_user) { create(:admin_user) } it "includes all order cycles" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 2, fee_type: "Shipment") expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor A") @@ -183,7 +183,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let!(:current_user) { distributor_a.owner } it "does not include unrelated order cycles" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_type: "Shipment") expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor A") @@ -225,7 +225,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { start_at: timestamp } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 0, fee_type: "Shipment", customer_name: "Customer A") expect_total_matches(totals, 1, fee_type: "Shipment", customer_name: "Customer B") @@ -237,7 +237,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { end_at: timestamp } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_type: "Shipment", customer_name: "Customer A") expect_total_matches(totals, 1, fee_type: "Shipment", customer_name: "Customer B") @@ -267,7 +267,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { distributor_ids: [distributor_a.id, distributor_b.id] } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor A") expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor B") @@ -305,7 +305,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { producer_ids: [producer_a.id, producer_b.id] } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_name: "Fee A", enterprise_name: "Producer A") expect_total_matches(totals, 1, fee_name: "Fee B", enterprise_name: "Producer B") @@ -342,7 +342,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { order_cycle_ids: [order_cycle_a.id, order_cycle_b.id] } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor A") expect_total_matches(totals, 1, fee_type: "Shipment", enterprise_name: "Distributor B") @@ -362,7 +362,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do let(:parameters_attributes) { { enterprise_fee_ids: [fee_a.id, fee_b.id] } } it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_name: "Fee A") expect_total_matches(totals, 1, fee_name: "Fee B") @@ -390,7 +390,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do end it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_name: "Shipping A") expect_total_matches(totals, 1, fee_name: "Shipping B") @@ -418,7 +418,7 @@ describe OrderManagement::Reports::EnterpriseFeeSummary::ReportService do end it "filters entries" do - totals = service.enterprise_fee_type_totals.list + totals = service.list expect_total_matches(totals, 1, fee_name: "Payment A") expect_total_matches(totals, 1, fee_name: "Payment B")