From 453b2a99de4b1989dc473386613a53188c2ce82e Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 23 Nov 2018 12:00:45 +0100 Subject: [PATCH] Rename redundant #restart_checkout to #call --- app/controllers/checkout_controller.rb | 4 ++-- app/services/restart_checkout.rb | 2 +- spec/controllers/checkout_controller_spec.rb | 8 +++----- spec/services/restart_checkout_spec.rb | 6 +++--- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 59017f7ed5..3ffe896db1 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -18,7 +18,7 @@ class CheckoutController < Spree::CheckoutController # This is only required because of spree_paypal_express. If we implement # a version of paypal that uses this controller, and more specifically # the #update_failed method, then we can remove this call - RestartCheckout.new(@order).restart_checkout + RestartCheckout.new(@order).call end def update @@ -139,7 +139,7 @@ class CheckoutController < Spree::CheckoutController def update_failed clear_ship_address - RestartCheckout.new(@order).restart_checkout + RestartCheckout.new(@order).call respond_to do |format| format.html do diff --git a/app/services/restart_checkout.rb b/app/services/restart_checkout.rb index 9bbd476197..79ef9acdb5 100644 --- a/app/services/restart_checkout.rb +++ b/app/services/restart_checkout.rb @@ -4,7 +4,7 @@ class RestartCheckout @order = order end - def restart_checkout + def call return if order.cart? reset_state_to_cart diff --git a/spec/controllers/checkout_controller_spec.rb b/spec/controllers/checkout_controller_spec.rb index 59a08811f9..43c937a892 100644 --- a/spec/controllers/checkout_controller_spec.rb +++ b/spec/controllers/checkout_controller_spec.rb @@ -189,7 +189,7 @@ describe CheckoutController, type: :controller do describe "Paypal routing" do let(:payment_method) { create(:payment_method, type: "Spree::Gateway::PayPalExpress") } - let(:restart_checkout) { instance_double(RestartCheckout, restart_checkout: true) } + let(:restart_checkout) { instance_double(RestartCheckout, call: true) } before do allow(controller).to receive(:current_distributor) { distributor } @@ -208,9 +208,7 @@ describe CheckoutController, type: :controller do end describe "#update_failed" do - let(:restart_checkout) do - instance_double(RestartCheckout, restart_checkout: true) - end + let(:restart_checkout) { instance_double(RestartCheckout, call: true) } before do controller.instance_variable_set(:@order, order) @@ -219,7 +217,7 @@ describe CheckoutController, type: :controller do it "clears the shipping address and restarts the checkout" do expect(controller).to receive(:clear_ship_address) - expect(restart_checkout).to receive(:restart_checkout) + expect(restart_checkout).to receive(:call) expect(controller).to receive(:respond_to) controller.send(:update_failed) diff --git a/spec/services/restart_checkout_spec.rb b/spec/services/restart_checkout_spec.rb index 56451f8b15..1337e2c581 100644 --- a/spec/services/restart_checkout_spec.rb +++ b/spec/services/restart_checkout_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe RestartCheckout do let(:order) { create(:order) } - describe "#restart_checkout" do + describe "#call" do context "when the order is already in the 'cart' state" do it "does nothing" do expect(order).to_not receive(:restart_checkout!) - RestartCheckout.new(order).restart_checkout + RestartCheckout.new(order).call end end @@ -25,7 +25,7 @@ describe RestartCheckout do # with a state other than 'pending' when the order has not been # completed, so this is not a case that requires testing. it "resets the order state, and clears incomplete shipments and payments" do - RestartCheckout.new(order).restart_checkout + RestartCheckout.new(order).call expect(order.state).to eq 'cart' expect(order.shipping_method_id).to eq nil