From 359fd1ac98537c52f02fa2e78b31a959de2cfdf4 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 14 May 2020 10:36:10 +1000 Subject: [PATCH 1/3] Improve readability of report spec --- .rubocop_manual_todo.yml | 1 - .../order_and_distributor_report_spec.rb | 22 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.rubocop_manual_todo.yml b/.rubocop_manual_todo.yml index f02f99e9b5c..e55124201f7 100644 --- a/.rubocop_manual_todo.yml +++ b/.rubocop_manual_todo.yml @@ -226,7 +226,6 @@ Layout/LineLength: - spec/lib/open_food_network/group_buy_report_spec.rb - spec/lib/open_food_network/lettuce_share_report_spec.rb - spec/lib/open_food_network/option_value_namer_spec.rb - - spec/lib/open_food_network/order_and_distributor_report_spec.rb - spec/lib/open_food_network/order_cycle_form_applicator_spec.rb - spec/lib/open_food_network/order_cycle_permissions_spec.rb - spec/lib/open_food_network/order_grouper_spec.rb diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb index 5b9e564b218..ddb59bdc876 100644 --- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb +++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb @@ -8,11 +8,16 @@ module OpenFoodNetwork subject = OrderAndDistributorReport.new nil header = subject.header - expect(header).to eq(['Order date', 'Order Id', - 'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City', - 'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost', - 'Payment Method', - 'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', 'Shipping Method', 'Shipping instructions']) + expect(header).to eq( + [ + 'Order date', 'Order Id', + 'Customer Name', 'Customer Email', 'Customer Phone', 'Customer City', + 'SKU', 'Item name', 'Variant', 'Quantity', 'Max Quantity', 'Cost', 'Shipping Cost', + 'Payment Method', + 'Distributor', 'Distributor address', 'Distributor city', 'Distributor postcode', + 'Shipping Method', 'Shipping instructions' + ] + ) end context 'with completed order' do @@ -21,7 +26,12 @@ module OpenFoodNetwork let(:product) { create(:product) } let(:shipping_method) { create(:shipping_method) } let(:shipping_instructions) { 'pick up on thursday please!' } - let(:order) { create(:order, state: 'complete', completed_at: Time.zone.now, distributor: distributor, bill_address: bill_address, special_instructions: shipping_instructions) } + let(:order) { + create(:order, + state: 'complete', completed_at: Time.zone.now, + distributor: distributor, bill_address: bill_address, + special_instructions: shipping_instructions) + } let(:payment_method) { create(:payment_method, distributors: [distributor]) } let(:payment) { create(:payment, payment_method: payment_method, order: order) } let(:line_item) { create(:line_item_with_shipment, product: product, order: order) } From 19f7f048160bd792937fd656bd7ca0de6311439b Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 14 May 2020 12:04:08 +1000 Subject: [PATCH 2/3] Add spec for report bug --- .../order_and_distributor_report_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb index ddb59bdc876..973360437a4 100644 --- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb +++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb @@ -47,6 +47,7 @@ module OpenFoodNetwork table = subject.table + expect(table.size).to eq 1 expect(table[0]).to eq([ order.reload.completed_at.strftime("%F %T"), order.id, @@ -70,6 +71,17 @@ module OpenFoodNetwork shipping_instructions ]) end + + it "prints one row per line item" do + pending "Each line item is shown multiple times when there is more than one item in the order" + + create(:line_item_with_shipment, order: order) + + subject = OrderAndDistributorReport.new(create(:admin_user), {}, true) + + table = subject.table + expect(table.size).to eq 2 # currently 4 + end end end end From 2d95e9ebc04a871336c9c10e6ee644d535c9fd55 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 14 May 2020 14:07:16 +1000 Subject: [PATCH 3/3] List each order only once in report --- lib/open_food_network/order_and_distributor_report.rb | 4 +++- .../open_food_network/order_and_distributor_report_spec.rb | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/open_food_network/order_and_distributor_report.rb b/lib/open_food_network/order_and_distributor_report.rb index 570096cb237..48435e4bd76 100644 --- a/lib/open_food_network/order_and_distributor_report.rb +++ b/lib/open_food_network/order_and_distributor_report.rb @@ -34,7 +34,9 @@ def header end def search - @permissions.visible_orders.complete.not_state(:canceled).search(@params[:q]) + @permissions.visible_orders.select("DISTINCT spree_orders.*"). + complete.not_state(:canceled). + search(@params[:q]) end def table diff --git a/spec/lib/open_food_network/order_and_distributor_report_spec.rb b/spec/lib/open_food_network/order_and_distributor_report_spec.rb index 973360437a4..616af0fc6ca 100644 --- a/spec/lib/open_food_network/order_and_distributor_report_spec.rb +++ b/spec/lib/open_food_network/order_and_distributor_report_spec.rb @@ -73,14 +73,12 @@ module OpenFoodNetwork end it "prints one row per line item" do - pending "Each line item is shown multiple times when there is more than one item in the order" - create(:line_item_with_shipment, order: order) subject = OrderAndDistributorReport.new(create(:admin_user), {}, true) table = subject.table - expect(table.size).to eq 2 # currently 4 + expect(table.size).to eq 2 end end end