From 13383316afa5df7fdd60278779fda7d3cc274dcd Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Thu, 23 Feb 2023 08:11:11 +0100 Subject: [PATCH] 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