From 2e4a8f8ae84510fd23d2c4989b2cf442963ed83c Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 27 Nov 2022 16:44:50 +0100 Subject: [PATCH 1/4] Fixes deprecation warnings on payment_spec --- spec/models/spree/payment_spec.rb | 71 +++++++++++++++++-------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/spec/models/spree/payment_spec.rb b/spec/models/spree/payment_spec.rb index 16bb1d7a9c..64029db600 100644 --- a/spec/models/spree/payment_spec.rb +++ b/spec/models/spree/payment_spec.rb @@ -143,7 +143,7 @@ describe Spree::Payment do end it "should call authorize on the gateway with the currency code" do - payment.stub currency: 'GBP' + allow(payment).to receive(:currency) { "GBP" } expect(payment.payment_method).to receive(:authorize).with( amount_in_cents, card, hash_including({ currency: "GBP" }) ).and_return(success_response) @@ -157,7 +157,7 @@ describe Spree::Payment do context "when gateway does not match the environment" do it "should raise an exception" do - gateway.stub environment: "foo" + allow(gateway).to receive(:environment) { "foo" } expect { payment.authorize! }.to raise_error(Spree::Core::GatewayError) end end @@ -200,7 +200,7 @@ describe Spree::Payment do context "if unsuccessful" do it "should mark payment as failed" do - gateway.stub(:authorize).and_return(failed_response) + allow(gateway).to receive(:authorize).and_return(failed_response) expect(payment).to receive(:failure) expect(payment).to_not receive(:pend) expect { @@ -224,7 +224,7 @@ describe Spree::Payment do context "when gateway does not match the environment" do it "should raise an exception" do - gateway.stub environment: "foo" + allow(gateway).to receive(:environment) { "foo" } expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError) end end @@ -250,7 +250,7 @@ describe Spree::Payment do context "if unsuccessful" do it "should make payment failed" do - gateway.stub(:purchase).and_return(failed_response) + allow(gateway).to receive(:purchase).and_return(failed_response) expect(payment).to receive(:failure) expect(payment).not_to receive(:pend) expect { payment.purchase! }.to raise_error(Spree::Core::GatewayError) @@ -260,7 +260,7 @@ describe Spree::Payment do context "#capture" do before do - payment.stub(:complete).and_return(true) + allow(payment).to receive(:complete).and_return(true) end context "when payment is pending" do @@ -279,7 +279,7 @@ describe Spree::Payment do end it "should store the response_code" do - gateway.stub capture: success_response + allow(gateway).to receive(:capture).and_return(success_response) payment.capture! expect(payment.response_code).to eq('123') end @@ -287,7 +287,7 @@ describe Spree::Payment do context "if unsuccessful" do it "should not make payment complete" do - gateway.stub capture: failed_response + allow(gateway).to receive(:capture).and_return(failed_response) expect(payment).to receive(:failure) expect(payment).to_not receive(:complete) expect { payment.capture! }.to raise_error(Spree::Core::GatewayError) @@ -315,7 +315,7 @@ describe Spree::Payment do context "when profiles are supported" do it "should call payment_gateway.void with the payment's response_code" do - gateway.stub payment_profiles_supported?: true + allow(gateway).to receive(:payment_profiles_supported) { true } expect(gateway).to receive(:void).with('123', card, anything).and_return(success_response) payment.void_transaction! @@ -324,8 +324,9 @@ describe Spree::Payment do context "when profiles are not supported" do it "should call payment_gateway.void with the payment's response_code" do - gateway.stub payment_profiles_supported?: false - expect(gateway).to receive(:void).with('123', anything).and_return(success_response) + allow(gateway).to receive(:payment_profiles_supported) { false } + expect(gateway).to receive(:void).with('123', card, + anything).and_return(success_response) payment.void_transaction! end end @@ -338,7 +339,7 @@ describe Spree::Payment do context "when gateway does not match the environment" do it "should raise an exception" do payment = build_stubbed(:payment, payment_method: gateway) - gateway.stub environment: "foo" + allow(gateway).to receive(:environment) { "foo" } expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError) end end @@ -354,7 +355,7 @@ describe Spree::Payment do context "if unsuccessful" do it "should not void the payment" do - gateway.stub void: failed_response + allow(gateway).to receive(:void).and_return(failed_response) expect(payment).to_not receive(:void) expect { payment.void_transaction! }.to raise_error(Spree::Core::GatewayError) end @@ -394,8 +395,8 @@ describe Spree::Payment do context "when outstanding_balance is less than payment amount" do before do - payment.order.stub outstanding_balance: 10 - payment.stub credit_allowed: 1000 + allow(payment.order).to receive(:outstanding_balance) { 10 } + allow(payment).to receive(:credit_allowed) { 1000 } end it "should call credit on the gateway with the credit amount and response_code" do @@ -420,7 +421,7 @@ describe Spree::Payment do context "when outstanding_balance is equal to payment amount" do before do - payment.order.stub outstanding_balance: payment.amount + allow(payment.order).to receive(:outstanding_balance) { payment.amount } end it "should call credit on the gateway with the credit amount and response_code" do @@ -433,7 +434,7 @@ describe Spree::Payment do context "when outstanding_balance is greater than payment amount" do before do - payment.order.stub outstanding_balance: 101 + allow(payment.order).to receive(:outstanding_balance) { 101 } end it "should call credit on the gateway with the original payment amount and response_code" do @@ -452,7 +453,7 @@ describe Spree::Payment do context "when gateway does not match the environment" do it "should raise an exception" do payment = build_stubbed(:payment, payment_method: gateway) - gateway.stub environment: "foo" + allow(gateway).to receive(:environment) { "foo" } expect { payment.credit! }.to raise_error(Spree::Core::GatewayError) end end @@ -498,8 +499,8 @@ describe Spree::Payment do context "when response is unsuccessful" do it "should not create a payment" do - gateway.stub credit: failed_response - Spree::Payment.should_not_receive(:create) + allow(gateway).to receive(:credit).and_return(failed_response) + expect(Spree::Payment).not_to receive(:create) expect { payment.credit! }.to raise_error(Spree::Core::GatewayError) end end @@ -530,7 +531,7 @@ describe Spree::Payment do context "raises no error if source is not specified" do specify do payment = build_stubbed(:payment, source: nil, payment_method: gateway) - payment.payment_method.stub(source_required?: false) + allow(payment.payment_method).to receive(:source_required?) { false } expect { payment.process! }.not_to raise_error end end @@ -539,9 +540,9 @@ describe Spree::Payment do context "#credit_allowed" do it "is the difference between offsets total and payment amount" do payment = build_stubbed(:payment, amount: 100) - payment.stub(:offsets_total).and_return(0) + allow(payment).to receive(:offsets_total) { 0 } expect(payment.credit_allowed).to eq(100) - payment.stub(:offsets_total).and_return(80) + allow(payment).to receive(:offsets_total) { 80 } expect(payment.credit_allowed).to eq(20) end end @@ -549,12 +550,12 @@ describe Spree::Payment do context "#can_credit?" do it "is true if credit_allowed > 0" do payment = build_stubbed(:payment) - payment.stub(:credit_allowed).and_return(100) + allow(payment).to receive(:credit_allowed) { 100 } expect(payment.can_credit?).to be true end it "is false if credit_allowed is 0" do payment = build_stubbed(:payment) - payment.stub(:credit_allowed).and_return(0) + allow(payment).to receive(:credit_allowed) { 0 } expect(payment.can_credit?).to be false end end @@ -569,13 +570,13 @@ describe Spree::Payment do payment.order = create(:order) payment.state = 'completed' - payment.stub(:credit_allowed).and_return(10) + allow(payment).to receive(:credit_allowed) { 10 } payment.partial_credit(10) expect(payment).to be_processing end it "calls credit on the source with the payment and amount" do payment.state = 'completed' - payment.stub(:credit_allowed).and_return(10) + allow(payment).to receive(:credit_allowed) { 10 } expect(payment).to receive(:credit!).with(10) payment.partial_credit(10) end @@ -584,7 +585,7 @@ describe Spree::Payment do it "should not call credit on the source" do payment = build_stubbed(:payment) payment.state = 'completed' - payment.stub(:credit_allowed).and_return(10) + allow(payment).to receive(:credit_allowed) { 10 } payment.partial_credit(20) expect(payment).to be_completed end @@ -636,8 +637,8 @@ describe Spree::Payment do context "when profiles are supported" do before do - gateway.stub payment_profiles_supported?: true - payment.source.stub has_payment_profile?: false + allow(gateway).to receive(:payment_profiles_supported?) { true } + allow(payment.source).to receive(:has_payment_profile?) { false } end context "when there is an error connecting to the gateway" do @@ -679,14 +680,16 @@ describe Spree::Payment do end context "when profiles are not supported" do - before { gateway.stub payment_profiles_supported?: false } + before do + allow(gateway).to receive(:payment_profiles_supported?) { false } + end it "should not create a payment profile" do gateway.name = 'Gateway' gateway.distributors << create(:distributor_enterprise) gateway.save! - gateway.should_not_receive :create_profile + expect(gateway).to_not receive :create_profile payment = Spree::Payment.create( amount: 100, order: create(:order), @@ -748,7 +751,9 @@ describe Spree::Payment do # Regression test for #2216 context "#gateway_options" do - before { order.stub(last_ip_address: "192.168.1.1") } + before do + allow(order).to receive(:last_ip_address) { "192.168.1.1" } + end it "contains an IP" do expect(payment.gateway_options[:ip]).to eq(order.last_ip_address) From 8ee5050a490b05f08e4c4098ba5215cd4fc0c070 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 5 Dec 2022 00:31:53 +0100 Subject: [PATCH 2/4] Fixes deprecation warnings on tax_rate_spec --- spec/models/spree/tax_rate_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/models/spree/tax_rate_spec.rb b/spec/models/spree/tax_rate_spec.rb index 34877fade4..60766a4284 100644 --- a/spec/models/spree/tax_rate_spec.rb +++ b/spec/models/spree/tax_rate_spec.rb @@ -61,7 +61,7 @@ module Spree end it "should return an empty array" do - order.stub tax_zone: @zone + allow(order).to receive(:tax_zone) { @zone } expect(Spree::TaxRate.match(order)).to eq [] end @@ -73,7 +73,8 @@ module Spree calculator: calculator ) - order.stub tax_zone: @zone + allow(order).to receive(:tax_zone) { @zone } + expect(Spree::TaxRate.match(order)).to eq [rate] end @@ -92,7 +93,8 @@ module Spree calculator: ::Calculator::FlatRate.new ) - order.stub tax_zone: @zone + allow(order).to receive(:tax_zone) { @zone } + expect(Spree::TaxRate.match(order)).to eq [rate1, rate2] end @@ -100,7 +102,8 @@ module Spree before do sub_zone = create(:zone, name: "State Zone", zone_members: []) sub_zone.zone_members.create(zoneable: create(:state, country: country)) - order.stub tax_zone: sub_zone + allow(order).to receive(:tax_zone) { sub_zone } + @rate = Spree::TaxRate.create( amount: 1, zone: @zone, @@ -134,8 +137,8 @@ module Spree context "when the order has the same tax zone" do before do - order.stub tax_zone: @zone - order.stub billing_address: tax_address + allow(order).to receive(:tax_zone) { @zone } + allow(order).to receive(:billing_address) { tax_address } end let(:tax_address) { build_stubbed(:address) } From 70193539b2c9a508932edb1183a17b4ce20f36c9 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 6 Dec 2022 15:42:10 +0000 Subject: [PATCH 3/4] Fixes deprecation warnings on parameters_spec --- spec/lib/reports/enterprise_fee_summary/parameters_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/reports/enterprise_fee_summary/parameters_spec.rb b/spec/lib/reports/enterprise_fee_summary/parameters_spec.rb index 85689cab90..9a3967edf5 100644 --- a/spec/lib/reports/enterprise_fee_summary/parameters_spec.rb +++ b/spec/lib/reports/enterprise_fee_summary/parameters_spec.rb @@ -71,7 +71,7 @@ module Reporting let(:permissions) do Permissions.new(nil).tap do |instance| - instance.stub(allowed_order_cycles: [order_cycle]) + allow(instance).to receive(:allowed_order_cycles) { [order_cycle] } end end From 2c18e97fb81425ce3e14550010425cca0ccefc73 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Thu, 8 Dec 2022 18:42:48 +0000 Subject: [PATCH 4/4] Fixes deprecation warnings on authorizer_spec --- spec/lib/reports/enterprise_fee_summary/authorizer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/reports/enterprise_fee_summary/authorizer_spec.rb b/spec/lib/reports/enterprise_fee_summary/authorizer_spec.rb index f629c84fae..9409ad5f04 100644 --- a/spec/lib/reports/enterprise_fee_summary/authorizer_spec.rb +++ b/spec/lib/reports/enterprise_fee_summary/authorizer_spec.rb @@ -170,7 +170,7 @@ module Reporting def stub_model(model, params) model.new.tap do |instance| - instance.stub(params) + allow(instance).to receive_messages(params) end end end