From a7e6760028f5394bf2cd62f9198ad7653231163c Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 23 Feb 2023 07:09:49 +0100 Subject: [PATCH 01/14] limit users who can update shipping/payment method of an order cycle --- app/services/order_cycle_form.rb | 66 ++++++++- spec/services/order_cycle_form_spec.rb | 195 +++++++++++++++++++++---- 2 files changed, 229 insertions(+), 32 deletions(-) diff --git a/app/services/order_cycle_form.rb b/app/services/order_cycle_form.rb index 52a3ce10ef..9f99d6ffa6 100644 --- a/app/services/order_cycle_form.rb +++ b/app/services/order_cycle_form.rb @@ -30,8 +30,10 @@ class OrderCycleForm order_cycle.schedule_ids = schedule_ids if parameter_specified?(:schedule_ids) order_cycle.save! apply_exchange_changes - attach_selected_distributor_payment_methods - attach_selected_distributor_shipping_methods + if can_update_selected_payment_or_shipping_methods? + attach_selected_distributor_payment_methods + attach_selected_distributor_shipping_methods + end sync_subscriptions true end @@ -61,14 +63,29 @@ class OrderCycleForm def attach_selected_distributor_payment_methods return if @selected_distributor_payment_method_ids.nil? - order_cycle.selected_distributor_payment_method_ids = selected_distributor_payment_method_ids + if distributor_only? + payment_method_ids = order_cycle.selected_distributor_payment_method_ids + payment_method_ids -= user_distributor_payment_method_ids + payment_method_ids += user_only_selected_distributor_payment_method_ids + order_cycle.selected_distributor_payment_method_ids = payment_method_ids + else + order_cycle.selected_distributor_payment_method_ids = selected_distributor_payment_method_ids + end order_cycle.save! end def attach_selected_distributor_shipping_methods return if @selected_distributor_shipping_method_ids.nil? - order_cycle.selected_distributor_shipping_method_ids = selected_distributor_shipping_method_ids + if distributor_only? + shipping_method_ids = order_cycle.selected_distributor_shipping_method_ids + shipping_method_ids -= user_distributor_shipping_method_ids + shipping_method_ids += user_only_selected_distributor_shipping_method_ids + order_cycle.selected_distributor_shipping_method_ids = shipping_method_ids + else + order_cycle.selected_distributor_shipping_method_ids = selected_distributor_shipping_method_ids + end + order_cycle.save! end @@ -99,6 +116,10 @@ class OrderCycleForm @selected_distributor_payment_method_ids end + def user_only_selected_distributor_payment_method_ids + user_distributor_payment_method_ids.intersection(selected_distributor_payment_method_ids) + end + def selected_distributor_shipping_method_ids @selected_distributor_shipping_method_ids = ( attachable_distributor_shipping_method_ids & @@ -112,6 +133,10 @@ class OrderCycleForm @selected_distributor_shipping_method_ids end + def user_only_selected_distributor_shipping_method_ids + user_distributor_shipping_method_ids.intersection(selected_distributor_shipping_method_ids) + end + def build_schedule_ids return unless parameter_specified?(:schedule_ids) @@ -160,4 +185,37 @@ class OrderCycleForm def new_schedule_ids @order_cycle.schedule_ids - existing_schedule_ids end + + def can_update_selected_payment_or_shipping_methods? + @user.admin? || coordinator? || distributor? + end + + def coordinator? + @user.enterprises.include?(@order_cycle.coordinator) + end + + def distributor? + !user_distributors_ids.empty? + end + + def distributor_only? + distributor? && !@user.admin? && !coordinator? + end + + def user_distributors_ids + @user_distributors_ids ||= @user.enterprises.pluck(:id) + .intersection(@order_cycle.distributors.pluck(:id)) + end + + def user_distributor_payment_method_ids + @user_distributor_payment_method_ids ||= + DistributorPaymentMethod.where(distributor_id: user_distributors_ids) + .pluck(:id) + end + + def user_distributor_shipping_method_ids + @user_distributor_shipping_method_ids ||= + DistributorShippingMethod.where(distributor_id: user_distributors_ids) + .pluck(:id) + end end diff --git a/spec/services/order_cycle_form_spec.rb b/spec/services/order_cycle_form_spec.rb index a9ed405458..18e7b03fcd 100644 --- a/spec/services/order_cycle_form_spec.rb +++ b/spec/services/order_cycle_form_spec.rb @@ -223,22 +223,93 @@ describe OrderCycleForm do context "updating payment methods" do context "and it's valid" do - it "saves the changes" do - distributor = create(:distributor_enterprise) - distributor_payment_method = create( - :payment_method, - distributors: [distributor] - ).distributor_payment_methods.first - order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + let!(:distributor){ create(:distributor_enterprise) } + let!(:payment_method){ create(:payment_method, distributors: [distributor]) } + let!(:payment_method2){ create(:payment_method, distributors: [distributor]) } + let!(:distributor_payment_method){ payment_method.distributor_payment_methods.first } + let!(:distributor_payment_method2){ payment_method2.distributor_payment_methods.first } + let!(:supplier){ create(:supplier_enterprise) } + context "the submitter is a coordinator" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) - form = OrderCycleForm.new( - order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, - order_cycle.coordinator - ) + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + order_cycle.coordinator.users.first + ) - expect(form.save).to be true - expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + expect(form.save).to be true + expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + end + end + + context "submitter is a supplier" do + it "doesn't save the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor], + suppliers: [supplier]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + supplier.users.first + ) + + expect(form).not_to receive(:attach_selected_distributor_payment_methods) + expect(order_cycle.distributor_payment_methods).to match_array [ + distributor_payment_method, distributor_payment_method2 + ] + end + end + + context "submitter is an admin" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + create(:admin_user) + ) + + expect(form.save).to be true + expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + end + end + + context "submitter is a distributor" do + context "can update his own payment methods" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + distributor.users.first + ) + + expect(form.save).to be true + expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + end + end + context "can't update other distributors' payment methods" do + let(:distributor2){ create(:distributor_enterprise) } + it "doesn't save the changes" do + order_cycle = create(:distributor_order_cycle, + distributors: [distributor, distributor2]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + distributor2.users.first + ) + + expect(form).not_to receive(:attach_selected_distributor_payment_methods) + expect(order_cycle.distributor_payment_methods).to match_array [ + distributor_payment_method, distributor_payment_method2 + ] + end + end end end @@ -271,22 +342,90 @@ describe OrderCycleForm do context "updating shipping methods" do context "and it's valid" do - it "saves the changes" do - distributor = create(:distributor_enterprise) - distributor_shipping_method = create( - :shipping_method, - distributors: [distributor] - ).distributor_shipping_methods.first - order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + let(:distributor){ create(:distributor_enterprise) } + let(:shipping_method){ create(:shipping_method, distributors: [distributor]) } + let(:shipping_method2){ create(:shipping_method, distributors: [distributor]) } + let(:distributor_shipping_method){ shipping_method.distributor_shipping_methods.first } + let(:distributor_shipping_method2){ shipping_method2.distributor_shipping_methods.first } + let(:supplier){ create(:supplier_enterprise) } + context "the submitter is a coordinator" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) - form = OrderCycleForm.new( - order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, - order_cycle.coordinator - ) + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + order_cycle.coordinator.users.first + ) - expect(form.save).to be true - expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + expect(form.save).to be true + expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + end + end + context "submitter is a supplier" do + it "doesn't save the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor], + suppliers: [supplier]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + supplier.users.first + ) + + expect(form).not_to receive(:attach_selected_distributor_shipping_methods) + expect(order_cycle.distributor_shipping_methods).to match_array [ + distributor_shipping_method, distributor_shipping_method2 + ] + end + end + context "submitter is an admin" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + create(:admin_user) + ) + + expect(form.save).to be true + expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + end + end + context "submitter is a distributor" do + context "can update his own shipping methods" do + it "saves the changes" do + order_cycle = create(:distributor_order_cycle, distributors: [distributor]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + distributor.users.first + ) + + expect(form.save).to be true + expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + end + end + context "can't update other distributors' shipping methods" do + let(:distributor2){ create(:distributor_enterprise) } + it "doesn't save the changes" do + order_cycle = create(:distributor_order_cycle, + distributors: [distributor, distributor2]) + + form = OrderCycleForm.new( + order_cycle, + { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + distributor2.users.first + ) + + expect(form).not_to receive(:attach_selected_distributor_shipping_methods) + expect(order_cycle.distributor_shipping_methods).to match_array [ + distributor_shipping_method, distributor_shipping_method2 + ] + end + end end end From e705aa51bd9f56657e8853ca817ff8abdb2f0ae9 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 23 Feb 2023 07:12:47 +0100 Subject: [PATCH 02/14] fix existing tests: OrderCycleForm expects an instance of Spree::User (and not an Enterprise) --- spec/services/order_cycle_form_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/services/order_cycle_form_spec.rb b/spec/services/order_cycle_form_spec.rb index 18e7b03fcd..3c6b18c685 100644 --- a/spec/services/order_cycle_form_spec.rb +++ b/spec/services/order_cycle_form_spec.rb @@ -331,7 +331,7 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, { selected_distributor_payment_method_ids: [distributor_payment_method_ii.id] }, - order_cycle.coordinator + order_cycle.coordinator.users.first ) expect(form.save).to be true @@ -447,7 +447,7 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, { selected_distributor_shipping_method_ids: [distributor_shipping_method_ii.id] }, - order_cycle.coordinator + order_cycle.coordinator.users.first ) expect(form.save).to be true From 28f0d6954037a5028b9696e21a02cdb13711c3ce Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 23 Feb 2023 07:22:49 +0100 Subject: [PATCH 03/14] Update app/services/order_cycle_form.rb Co-authored-by: David Cook --- app/services/order_cycle_form.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/services/order_cycle_form.rb b/app/services/order_cycle_form.rb index 9f99d6ffa6..e588358a3a 100644 --- a/app/services/order_cycle_form.rb +++ b/app/services/order_cycle_form.rb @@ -78,6 +78,10 @@ class OrderCycleForm return if @selected_distributor_shipping_method_ids.nil? if distributor_only? + # A distributor can only update methods associated with their own + # enterprise, so we load all previously selected methods, and replace + # only the distributor's methods with their selection (not touching other + # distributor's methods). shipping_method_ids = order_cycle.selected_distributor_shipping_method_ids shipping_method_ids -= user_distributor_shipping_method_ids shipping_method_ids += user_only_selected_distributor_shipping_method_ids From 13383316afa5df7fdd60278779fda7d3cc274dcd Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 23 Feb 2023 08:11:11 +0100 Subject: [PATCH 04/14] fix tests --- spec/services/order_cycle_form_spec.rb | 42 +++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/spec/services/order_cycle_form_spec.rb b/spec/services/order_cycle_form_spec.rb index 3c6b18c685..d673d300c3 100644 --- a/spec/services/order_cycle_form_spec.rb +++ b/spec/services/order_cycle_form_spec.rb @@ -226,21 +226,23 @@ describe OrderCycleForm do let!(:distributor){ create(:distributor_enterprise) } let!(:payment_method){ create(:payment_method, distributors: [distributor]) } let!(:payment_method2){ create(:payment_method, distributors: [distributor]) } - let!(:distributor_payment_method){ payment_method.distributor_payment_methods.first } - let!(:distributor_payment_method2){ payment_method2.distributor_payment_methods.first } + let!(:distributor_payment_method){ distributor.distributor_payment_methods.first.id } + let!(:distributor_payment_method2){ distributor.distributor_payment_methods.second.id } let!(:supplier){ create(:supplier_enterprise) } + context "the submitter is a coordinator" do it "saves the changes" do order_cycle = create(:distributor_order_cycle, distributors: [distributor]) form = OrderCycleForm.new( order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + { selected_distributor_payment_method_ids: [distributor_payment_method] }, order_cycle.coordinator.users.first ) - expect(form.save).to be true - expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + expect{ form.save }.to change{ order_cycle.distributor_payment_methods.pluck(:id) } + .from([distributor_payment_method, distributor_payment_method2]) + .to([distributor_payment_method]) end end @@ -251,14 +253,11 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + { selected_distributor_payment_method_ids: [distributor_payment_method] }, supplier.users.first ) - expect(form).not_to receive(:attach_selected_distributor_payment_methods) - expect(order_cycle.distributor_payment_methods).to match_array [ - distributor_payment_method, distributor_payment_method2 - ] + expect{ form.save }.to_not change{ order_cycle.distributor_payment_methods.pluck(:id) } end end @@ -268,12 +267,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + { selected_distributor_payment_method_ids: [distributor_payment_method2] }, create(:admin_user) ) - expect(form.save).to be true - expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + expect{ form.save }.to change{ order_cycle.distributor_payment_methods.pluck(:id) } + .from([distributor_payment_method, distributor_payment_method2]) + .to([distributor_payment_method2]) end end @@ -284,12 +284,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + { selected_distributor_payment_method_ids: [distributor_payment_method] }, distributor.users.first ) - expect(form.save).to be true - expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method] + expect{ form.save }.to change{ order_cycle.distributor_payment_methods.pluck(:id) } + .from([distributor_payment_method, distributor_payment_method2]) + .to([distributor_payment_method]) end end context "can't update other distributors' payment methods" do @@ -300,14 +301,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_payment_method_ids: [distributor_payment_method.id] }, + { selected_distributor_payment_method_ids: [distributor_payment_method] }, distributor2.users.first ) - expect(form).not_to receive(:attach_selected_distributor_payment_methods) - expect(order_cycle.distributor_payment_methods).to match_array [ - distributor_payment_method, distributor_payment_method2 - ] + expect{ form.save }.to_not change{ + order_cycle.distributor_payment_methods.pluck(:id) + } end end end From 25d8ce17374ea91468e5e7f586a20ea2052341ad Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 27 Feb 2023 15:56:14 +0100 Subject: [PATCH 05/14] fix shipping methods related tests --- spec/services/order_cycle_form_spec.rb | 64 +++++++++++++++----------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/spec/services/order_cycle_form_spec.rb b/spec/services/order_cycle_form_spec.rb index d673d300c3..2d0cbf46f4 100644 --- a/spec/services/order_cycle_form_spec.rb +++ b/spec/services/order_cycle_form_spec.rb @@ -334,19 +334,21 @@ describe OrderCycleForm do order_cycle.coordinator.users.first ) - expect(form.save).to be true - expect(order_cycle.distributor_payment_methods).to eq [distributor_payment_method_i] + expect{ form.save }.not_to change{ + order_cycle.distributor_payment_methods.pluck(:id) + }.from([distributor_payment_method_i.id]) end end end context "updating shipping methods" do context "and it's valid" do - let(:distributor){ create(:distributor_enterprise) } - let(:shipping_method){ create(:shipping_method, distributors: [distributor]) } - let(:shipping_method2){ create(:shipping_method, distributors: [distributor]) } - let(:distributor_shipping_method){ shipping_method.distributor_shipping_methods.first } - let(:distributor_shipping_method2){ shipping_method2.distributor_shipping_methods.first } + let!(:distributor){ create(:distributor_enterprise) } + let!(:shipping_method){ create(:shipping_method, distributors: [distributor]) } + let!(:shipping_method2){ create(:shipping_method, distributors: [distributor]) } + let!(:distributor_shipping_method){ distributor.distributor_shipping_methods.first.id } + let!(:distributor_shipping_method2){ distributor.distributor_shipping_methods.second.id } + let(:supplier){ create(:supplier_enterprise) } context "the submitter is a coordinator" do it "saves the changes" do @@ -354,12 +356,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + { selected_distributor_shipping_method_ids: [distributor_shipping_method] }, order_cycle.coordinator.users.first ) - expect(form.save).to be true - expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + expect{ form.save }.to change{ order_cycle.distributor_shipping_methods.pluck(:id) } + .from([distributor_shipping_method, distributor_shipping_method2]) + .to([distributor_shipping_method]) end end context "submitter is a supplier" do @@ -369,14 +372,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + { selected_distributor_shipping_method_ids: [distributor_shipping_method] }, supplier.users.first ) - expect(form).not_to receive(:attach_selected_distributor_shipping_methods) - expect(order_cycle.distributor_shipping_methods).to match_array [ - distributor_shipping_method, distributor_shipping_method2 - ] + expect{ form.save }.not_to change{ + order_cycle.distributor_shipping_methods.pluck(:id) + }.from([distributor_shipping_method, distributor_shipping_method2]) end end context "submitter is an admin" do @@ -385,12 +387,13 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + { selected_distributor_shipping_method_ids: [distributor_shipping_method] }, create(:admin_user) ) - expect(form.save).to be true - expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + expect{ form.save }.to change{ order_cycle.distributor_shipping_methods.pluck(:id) } + .from([distributor_shipping_method, distributor_shipping_method2]) + .to([distributor_shipping_method]) end end context "submitter is a distributor" do @@ -400,29 +403,38 @@ describe OrderCycleForm do form = OrderCycleForm.new( order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + { selected_distributor_shipping_method_ids: [distributor_shipping_method] }, distributor.users.first ) - expect(form.save).to be true - expect(order_cycle.distributor_shipping_methods).to eq [distributor_shipping_method] + expect{ form.save }.to change{ + order_cycle.distributor_shipping_methods.pluck(:id) + }.from([ + distributor_shipping_method, distributor_shipping_method2 + ]).to([distributor_shipping_method]) end end context "can't update other distributors' shipping methods" do - let(:distributor2){ create(:distributor_enterprise) } + let!(:distributor2){ create(:distributor_enterprise) } + let!(:shipping_method3){ create(:shipping_method, distributors: [distributor2]) } + let!(:distributor_shipping_method3){ + distributor2.distributor_shipping_methods.first.id + } it "doesn't save the changes" do order_cycle = create(:distributor_order_cycle, distributors: [distributor, distributor2]) form = OrderCycleForm.new( order_cycle, - { selected_distributor_shipping_method_ids: [distributor_shipping_method.id] }, + { selected_distributor_shipping_method_ids: [distributor_shipping_method] }, distributor2.users.first ) - expect(form).not_to receive(:attach_selected_distributor_shipping_methods) - expect(order_cycle.distributor_shipping_methods).to match_array [ - distributor_shipping_method, distributor_shipping_method2 + expect{ form.save }.not_to change{ + order_cycle.distributor_shipping_methods.pluck(:id) + }.from [ + distributor_shipping_method, distributor_shipping_method2, + distributor_shipping_method3 ] end end From eab8e2be6ce90d179ba86d1b4b6eb74dbcffe1af Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 27 Feb 2023 19:26:24 +0100 Subject: [PATCH 06/14] load exclusively the shipping methods that support all the shipping categories of the line items --- .../concerns/checkout_callbacks.rb | 25 +++++++++++++++++-- app/controllers/split_checkout_controller.rb | 2 +- app/views/split_checkout/_details.html.haml | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/checkout_callbacks.rb b/app/controllers/concerns/checkout_callbacks.rb index 4b6608b947..0227c51857 100644 --- a/app/controllers/concerns/checkout_callbacks.rb +++ b/app/controllers/concerns/checkout_callbacks.rb @@ -15,7 +15,10 @@ module CheckoutCallbacks prepend_before_action :require_distributor_chosen before_action :load_order, :associate_user, :load_saved_addresses, :load_saved_credit_cards - before_action :load_shipping_methods, if: -> { params[:step] == "details" } + before_action :load_shipping_methods, + :load_allowed_shipping_methods, if: -> { + params[:step] == "details" + } before_action :ensure_order_not_completed before_action :ensure_checkout_allowed @@ -47,7 +50,25 @@ module CheckoutCallbacks end def load_shipping_methods - @shipping_methods = available_shipping_methods.sort { |a, b| a.name.casecmp(b.name) } + @shipping_methods = sorted_available_shipping_methods + end + + def load_allowed_shipping_methods + @allowed_shipping_methods = sorted_available_shipping_methods.filter( + &method(:supports_all_products_shipping_categories?) + ) + end + + def sorted_available_shipping_methods + available_shipping_methods.sort { |a, b| a.name.casecmp(b.name) } + end + + def supports_all_products_shipping_categories?(shipping_method) + (products_shipping_categories - shipping_method.shipping_categories.pluck(:id)).empty? + end + + def products_shipping_categories + @products_shipping_categories ||= @order.products.pluck(:shipping_category_id).uniq end def redirect_to_shop? diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 752cec3010..57c3e148ab 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -24,7 +24,7 @@ class SplitCheckoutController < ::BaseController check_step if params[:step] recalculate_tax if params[:step] == "summary" - flash_error_when_no_shipping_method_available if available_shipping_methods.none? + flash_error_when_no_shipping_method_available if load_allowed_shipping_methods.none? end def update diff --git a/app/views/split_checkout/_details.html.haml b/app/views/split_checkout/_details.html.haml index e81c8c08a7..a82ac1ff97 100644 --- a/app/views/split_checkout/_details.html.haml +++ b/app/views/split_checkout/_details.html.haml @@ -77,7 +77,7 @@ - ship_method_description = nil - selected_shipping_method ||= @shipping_methods[0].id if @shipping_methods.length == 1 - - @shipping_methods.each do |shipping_method| + - @allowed_shipping_methods.each do |shipping_method| - ship_method_is_selected = shipping_method.id == selected_shipping_method.to_i %div.checkout-input.checkout-input-radio = fields_for shipping_method do |shipping_method_form| From 89037e160cadc3ae36500cf40ec82eff41a4f3b7 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 1 Mar 2023 10:29:48 +0100 Subject: [PATCH 07/14] Update app/controllers/concerns/checkout_callbacks.rb Co-authored-by: Maikel --- app/controllers/concerns/checkout_callbacks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/checkout_callbacks.rb b/app/controllers/concerns/checkout_callbacks.rb index 0227c51857..651f672940 100644 --- a/app/controllers/concerns/checkout_callbacks.rb +++ b/app/controllers/concerns/checkout_callbacks.rb @@ -54,7 +54,7 @@ module CheckoutCallbacks end def load_allowed_shipping_methods - @allowed_shipping_methods = sorted_available_shipping_methods.filter( + @allowed_shipping_methods ||= sorted_available_shipping_methods.filter( &method(:supports_all_products_shipping_categories?) ) end From 348f806bbed8682b35bc53554ab0a79818c2ae17 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Wed, 1 Mar 2023 10:41:57 +0100 Subject: [PATCH 08/14] remove load_shipping_methods --- app/controllers/concerns/checkout_callbacks.rb | 13 ++++--------- app/controllers/split_checkout_controller.rb | 2 +- app/views/split_checkout/_details.html.haml | 2 +- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controllers/concerns/checkout_callbacks.rb b/app/controllers/concerns/checkout_callbacks.rb index 651f672940..5bb44eb9f3 100644 --- a/app/controllers/concerns/checkout_callbacks.rb +++ b/app/controllers/concerns/checkout_callbacks.rb @@ -15,10 +15,9 @@ module CheckoutCallbacks prepend_before_action :require_distributor_chosen before_action :load_order, :associate_user, :load_saved_addresses, :load_saved_credit_cards - before_action :load_shipping_methods, - :load_allowed_shipping_methods, if: -> { - params[:step] == "details" - } + before_action :allowed_shipping_methods, if: -> { + params[:step] == "details" + } before_action :ensure_order_not_completed before_action :ensure_checkout_allowed @@ -49,11 +48,7 @@ module CheckoutCallbacks @selected_card = nil end - def load_shipping_methods - @shipping_methods = sorted_available_shipping_methods - end - - def load_allowed_shipping_methods + def allowed_shipping_methods @allowed_shipping_methods ||= sorted_available_shipping_methods.filter( &method(:supports_all_products_shipping_categories?) ) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 57c3e148ab..1fb8649a3f 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -24,7 +24,7 @@ class SplitCheckoutController < ::BaseController check_step if params[:step] recalculate_tax if params[:step] == "summary" - flash_error_when_no_shipping_method_available if load_allowed_shipping_methods.none? + flash_error_when_no_shipping_method_available if allowed_shipping_methods.none? end def update diff --git a/app/views/split_checkout/_details.html.haml b/app/views/split_checkout/_details.html.haml index a82ac1ff97..8b20be09fb 100644 --- a/app/views/split_checkout/_details.html.haml +++ b/app/views/split_checkout/_details.html.haml @@ -76,7 +76,7 @@ - display_ship_address = false - ship_method_description = nil - - selected_shipping_method ||= @shipping_methods[0].id if @shipping_methods.length == 1 + - selected_shipping_method ||= @allowed_shipping_methods[0].id if @allowed_shipping_methods.length == 1 - @allowed_shipping_methods.each do |shipping_method| - ship_method_is_selected = shipping_method.id == selected_shipping_method.to_i %div.checkout-input.checkout-input-radio From c1b60d88d655cad46b5f4d1a7966aa2dcc31cf95 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 28 Feb 2023 19:13:47 +0000 Subject: [PATCH 09/14] Adds coverage for CSV file download --- .../sales_tax_by_order/sales_tax_by_order.csv | 5 +++++ .../sales_tax_totals_by_order_spec.rb | 21 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv diff --git a/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv new file mode 100644 index 0000000000..14eb8c3a39 --- /dev/null +++ b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv @@ -0,0 +1,5 @@ +Distributor,Order Cycle,Order number,Tax Category,Tax Rate Name,Tax Rate,Total excl. tax ($),Tax,Total incl. tax ($),First Name,Last Name,Code,Email +Distributor,oc1,ORDER_NUMBER_1,tax_category,State,0.015,115.0,1.73,116.73,cfname,clname,ABC123,order1@example.com +Distributor,oc1,ORDER_NUMBER_1,tax_category,Country,0.025,115.0,2.88,117.88,cfname,clname,ABC123,order1@example.com +Distributor,oc1,ORDER_NUMBER_2,tax_category,State,0.015,215.0,3.23,218.23,c2fname,c2lname,DEF456,order2@example.com +Distributor,oc1,ORDER_NUMBER_2,tax_category,Country,0.025,215.0,5.38,220.38,c2fname,c2lname,DEF456,order2@example.com diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index eb9699c99b..812bd04cbc 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -105,7 +105,7 @@ describe "Sales Tax Totals By order" do it "generates the report" do login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" expect(page).to have_button("Go") click_on "Go" @@ -167,7 +167,7 @@ describe "Sales Tax Totals By order" do it "generates the report" do login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" expect(page).to have_button("Go") click_on "Go" @@ -335,7 +335,7 @@ describe "Sales Tax Totals By order" do login_as admin visit admin_reports_path - click_on I18n.t("admin.reports.sales_tax_totals_by_order") + click_on "Sales Tax Totals By Order" end it "should load all the orders" do @@ -423,5 +423,20 @@ describe "Sales Tax Totals By order" do expect(page.find("table.report__table tbody").text).to have_content(customer2_summary_row) expect(page).to have_selector(table_raw_selector, count: 6) end + + context "downloads files" do + let(:report_file) do + CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") + end + it 'as csv' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "CSV", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.csv/) + expect(CSV.read(downloaded_filename)).to eq(report_file) + end + end end end From 66485e2e16a359b9c3c4f8fbea5955ebe34c9ca6 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 28 Feb 2023 19:02:19 +0000 Subject: [PATCH 10/14] Adds coverage for XLSX file download --- .../sales_tax_by_order.xlsx | Bin 0 -> 4280 bytes .../sales_tax_totals_by_order_spec.rb | 25 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx diff --git a/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx b/spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..ad2870fd259b2caf949a22b49ffdfb0fdac92054 GIT binary patch literal 4280 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 Z;opI+2__&s{{=DjrGb5F+E>oM{R>%3KR^Hg literal 0 HcmV?d00001 diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index 812bd04cbc..7e03c1149c 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'system_helper' +require 'roo' describe "Sales Tax Totals By order" do # Scenarion 1: added tax @@ -428,6 +429,11 @@ describe "Sales Tax Totals By order" do let(:report_file) do CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") end + + let(:report_file_xlsx) do + File.open("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx") + end + it 'as csv' do expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty select "CSV", from: "report_format" @@ -437,6 +443,25 @@ describe "Sales Tax Totals By order" do expect(downloaded_filename).to match(/.*\.csv/) expect(CSV.read(downloaded_filename)).to eq(report_file) end + + it 'as xlsx' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "Spreadsheet", from: "report_format" + find("#display_summary_row").uncheck + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.xlsx/) + downloaded_xlsx = Roo::Excelx.new(downloaded_filename) + downloaded_content = [downloaded_xlsx.row(1), downloaded_xlsx.row(2), + downloaded_xlsx.row(3), downloaded_xlsx.row(4), + downloaded_xlsx.row(5)] + fixture_xlsx = Roo::Excelx.new(report_file_xlsx) + fixture_content = [fixture_xlsx.row(1), fixture_xlsx.row(2), fixture_xlsx.row(3), + fixture_xlsx.row(4), + fixture_xlsx.row(5)] + expect(downloaded_content).to eq(fixture_content) + end end end end From b99383185bf8844670d42007687e12e36e65fd52 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 1 Mar 2023 14:31:16 +0000 Subject: [PATCH 11/14] Adds coverage for PDF file download --- .../reports/sales_tax/sales_tax_totals_by_order_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index 7e03c1149c..a7148bf82d 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -462,6 +462,15 @@ describe "Sales Tax Totals By order" do fixture_xlsx.row(5)] expect(downloaded_content).to eq(fixture_content) end + + it 'as pdf' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "PDF", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.pdf/) + end end end end From 0cae0697690701476da38ffe9e688cda28d4ff87 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Mar 2023 12:45:36 +0000 Subject: [PATCH 12/14] Bump @floating-ui/dom from 1.2.1 to 1.2.3 Bumps [@floating-ui/dom](https://github.com/floating-ui/floating-ui/tree/HEAD/packages/dom) from 1.2.1 to 1.2.3. - [Release notes](https://github.com/floating-ui/floating-ui/releases) - [Commits](https://github.com/floating-ui/floating-ui/commits/@floating-ui/dom@1.2.3/packages/dom) --- updated-dependencies: - dependency-name: "@floating-ui/dom" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 4fe255a530..30dacb0336 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ }, "dependencies": { "@babel/preset-env": "^7.18.2", - "@floating-ui/dom": "^1.2.1", + "@floating-ui/dom": "^1.2.3", "@hotwired/turbo": "^7.3.0", "@rails/webpacker": "5.4.4", "babel-loader": "^8.2.3", diff --git a/yarn.lock b/yarn.lock index 5957681acc..19187ab282 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1397,17 +1397,17 @@ resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7" integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw== -"@floating-ui/core@^1.2.1": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.2.1.tgz#074182a1d277f94569c50a6b456e62585d463c8e" - integrity sha512-LSqwPZkK3rYfD7GKoIeExXOyYx6Q1O4iqZWwIehDNuv3Dv425FIAE8PRwtAx1imEolFTHgBEcoFHm9MDnYgPCg== +"@floating-ui/core@^1.2.2": + version "1.2.2" + resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.2.2.tgz#66f62cf1b7de2ed23a09c101808536e68caffaec" + integrity sha512-FaO9KVLFnxknZaGWGmNtjD2CVFuc0u4yeGEofoyXO2wgRA7fLtkngT6UB0vtWQWuhH3iMTZZ/Y89CMeyGfn8pA== -"@floating-ui/dom@^1.2.1": - version "1.2.1" - resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.2.1.tgz#8f93906e1a3b9f606ce78afb058e874344dcbe07" - integrity sha512-Rt45SmRiV8eU+xXSB9t0uMYiQ/ZWGE/jumse2o3i5RGlyvcbqOF4q+1qBnzLE2kZ5JGhq0iMkcGXUKbFe7MpTA== +"@floating-ui/dom@^1.2.3": + version "1.2.3" + resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.2.3.tgz#8dc6fbf799fbb5c29f705b54bdd51f3ab0ee03a2" + integrity sha512-lK9cZUrHSJLMVAdCvDqs6Ug8gr0wmqksYiaoj/bxj2gweRQkSuhg2/V6Jswz2KiQ0RAULbqw1oQDJIMpQ5GfGA== dependencies: - "@floating-ui/core" "^1.2.1" + "@floating-ui/core" "^1.2.2" "@hotwired/stimulus-webpack-helpers@^1.0.0": version "1.0.1" From 2814b1f3995b509c54ec488b929b28178df5529b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 3 Mar 2023 09:35:40 +0100 Subject: [PATCH 13/14] Update all locales with the latest Transifex translations --- config/locales/en_FR.yml | 1 + config/locales/en_GB.yml | 2 +- config/locales/fr.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/config/locales/en_FR.yml b/config/locales/en_FR.yml index b4c49d93d5..5bddf3d0d7 100644 --- a/config/locales/en_FR.yml +++ b/config/locales/en_FR.yml @@ -1335,6 +1335,7 @@ en_FR: payment_methods: Payment Methods Report delivery: Delivery Report sales_tax_totals_by_producer: Sales Tax Totals By Producer + sales_tax_totals_by_order: Sales Tax Totals By Order tax_types: Tax Types tax_rates: Tax Rates pack_by_customer: Pack By Customer diff --git a/config/locales/en_GB.yml b/config/locales/en_GB.yml index dc6434d409..fdbf47763b 100644 --- a/config/locales/en_GB.yml +++ b/config/locales/en_GB.yml @@ -2073,7 +2073,7 @@ en_GB: components_filters_clearfilters: "Clear all filters" groups_title: Groups groups_headline: Groups / regions - groups_text: "Every producer is unique. Every business has something different to offer. Our groups are collectives of producers, hubs and distributors who share something in common like location, farmers market or philosophy. This makes your shopping experience easier. So explore our groups and have the curating done for you." + groups_text: "Every producer is unique. Every business has something different to offer. Our groups are collectives of producers, hubs and distributors who share something in common, whether that's belonging to a local farmers market, specialising in a specific product, or sharing a philosophy. Explore our curated groups below." groups_search: "Search name or keyword" groups_no_groups: "No groups found" groups_about: "About Us" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index eacead75b3..cfa9aa7779 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1336,6 +1336,7 @@ fr: payment_methods: Rapport Méthodes de Paiement delivery: Rapport de Livraison sales_tax_totals_by_producer: Détail des montants de taxes par producteur + sales_tax_totals_by_order: Détail des montants de taxes par commande tax_types: Par type de taxe tax_rates: Par taux de taxe pack_by_customer: Préparation des commandes par Acheteur From 56b9c289551f263ef553b4960c3900514cdcb46b Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Wed, 1 Mar 2023 14:54:27 +0000 Subject: [PATCH 14/14] Splits test cases into respective context blocks Reduces code --- .../sales_tax_totals_by_order_spec.rb | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb index a7148bf82d..d06a141114 100644 --- a/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb +++ b/spec/system/admin/reports/sales_tax/sales_tax_totals_by_order_spec.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'system_helper' -require 'roo' describe "Sales Tax Totals By order" do # Scenarion 1: added tax @@ -425,51 +424,56 @@ describe "Sales Tax Totals By order" do expect(page).to have_selector(table_raw_selector, count: 6) end - context "downloads files" do - let(:report_file) do - CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") + describe "downloading" do + context "csv files" do + let(:report_file_csv) do + CSV.read("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.csv") + end + + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "CSV", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.csv/) + expect(CSV.read(downloaded_filename)).to eq(report_file_csv) + end end - let(:report_file_xlsx) do - File.open("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx") + context "xlsx files" do + let(:report_file_xlsx) do + File.open("spec/fixtures/reports/sales_tax_by_order/sales_tax_by_order.xlsx") + end + + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "Spreadsheet", from: "report_format" + find("#display_summary_row").uncheck + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.xlsx/) + downloaded_content = extract_xlsx_rows(downloaded_filename, 1..5) + fixture_content = extract_xlsx_rows(report_file_xlsx, 1..5) + expect(downloaded_content).to eq(fixture_content) + end + + def extract_xlsx_rows(file, range) + xlsx = Roo::Excelx.new(file) + range.map { |i| xlsx.row(i) } + end end - it 'as csv' do - expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty - select "CSV", from: "report_format" - click_on "Go" - wait_for_download - expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file - expect(downloaded_filename).to match(/.*\.csv/) - expect(CSV.read(downloaded_filename)).to eq(report_file) - end - - it 'as xlsx' do - expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty - select "Spreadsheet", from: "report_format" - find("#display_summary_row").uncheck - click_on "Go" - wait_for_download - expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file - expect(downloaded_filename).to match(/.*\.xlsx/) - downloaded_xlsx = Roo::Excelx.new(downloaded_filename) - downloaded_content = [downloaded_xlsx.row(1), downloaded_xlsx.row(2), - downloaded_xlsx.row(3), downloaded_xlsx.row(4), - downloaded_xlsx.row(5)] - fixture_xlsx = Roo::Excelx.new(report_file_xlsx) - fixture_content = [fixture_xlsx.row(1), fixture_xlsx.row(2), fixture_xlsx.row(3), - fixture_xlsx.row(4), - fixture_xlsx.row(5)] - expect(downloaded_content).to eq(fixture_content) - end - - it 'as pdf' do - expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty - select "PDF", from: "report_format" - click_on "Go" - wait_for_download - expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file - expect(downloaded_filename).to match(/.*\.pdf/) + context "pdf files" do + it 'downloads the file' do + expect(downloaded_filenames.length).to eq(0) # downloads folder should be empty + select "PDF", from: "report_format" + click_on "Go" + wait_for_download + expect(downloaded_filenames.length).to eq(1) # downloads folder should contain 1 file + expect(downloaded_filename).to match(/.*\.pdf/) + end end end end