From 26d81b2e170283ee430c5860e3c610219d1201ee Mon Sep 17 00:00:00 2001 From: Eric Saupe Date: Mon, 22 May 2017 12:05:09 +0100 Subject: [PATCH] Deprecate simple_current_order The `#simple_current_order` method is duplicating many of the functions already found in `#current_order`. `simple_current_order` was finds an order by token or user, updates ip_address, and creates an order if one is not found. All functions that are already accomplised in `#current_order` which also does more than `#simple_current_order` making it the preferred method. --- CHANGELOG.md | 3 +++ core/app/helpers/spree/base_helper.rb | 4 ++-- .../spree/core/controller_helpers/order.rb | 2 +- .../core/controller_helpers/order_spec.rb | 20 +++++++++++++++---- .../app/controllers/spree/store_controller.rb | 2 +- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c7159c7c6..236a3be3238 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Solidus 2.3.0 (master, unreleased) +- Deprecate `#simple_current_order` +[\#1915](https://github.com/solidusio/solidus/pull/1915) ([ericsaupe](https://github.com/ericsaupe)) + ## Solidus 2.2.1 (2017-05-09) - Fix migrating CreditCards to WalletPaymentSource [\#1898](https://github.com/solidusio/solidus/pull/1898) ([jhawthorn](https://github.com/jhawthorn)) diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb index 0eb942bd048..52d7b5756fc 100644 --- a/core/app/helpers/spree/base_helper.rb +++ b/core/app/helpers/spree/base_helper.rb @@ -4,11 +4,11 @@ def link_to_cart(text = nil) text = text ? h(text) : Spree.t(:cart) css_class = nil - if simple_current_order.nil? || simple_current_order.item_count.zero? + if current_order.nil? || current_order.item_count.zero? text = "#{text}: (#{Spree.t(:empty)})" css_class = 'empty' else - text = "#{text}: (#{simple_current_order.item_count}) #{simple_current_order.display_total.to_html}" + text = "#{text}: (#{current_order.item_count}) #{current_order.display_total.to_html}" css_class = 'full' end diff --git a/core/lib/spree/core/controller_helpers/order.rb b/core/lib/spree/core/controller_helpers/order.rb index 7f79701827d..44837f057cd 100644 --- a/core/lib/spree/core/controller_helpers/order.rb +++ b/core/lib/spree/core/controller_helpers/order.rb @@ -14,7 +14,6 @@ module Order helper_method :simple_current_order end - # Used in the link_to_cart helper. def simple_current_order return @simple_current_order if @simple_current_order @@ -27,6 +26,7 @@ def simple_current_order @simple_current_order = Spree::Order.new(current_order_params) end end + deprecate simple_current_order: :current_order, deprecator: Spree::Deprecation # The current incomplete order from the guest_token for use in cart and during checkout def current_order(options = {}) diff --git a/core/spec/lib/spree/core/controller_helpers/order_spec.rb b/core/spec/lib/spree/core/controller_helpers/order_spec.rb index 613fe060f2d..9c982af977a 100644 --- a/core/spec/lib/spree/core/controller_helpers/order_spec.rb +++ b/core/spec/lib/spree/core/controller_helpers/order_spec.rb @@ -19,14 +19,26 @@ class FakesController < ApplicationController describe '#simple_current_order' do it "returns an empty order" do - expect(controller.simple_current_order.item_count).to eq 0 + Spree::Deprecation.silence do + expect(controller.simple_current_order.item_count).to eq 0 + end end it 'returns Spree::Order instance' do - allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token })) - expect(controller.simple_current_order).to eq order + Spree::Deprecation.silence do + allow(controller).to receive_messages(cookies: double(signed: { guest_token: order.guest_token })) + expect(controller.simple_current_order).to eq order + end end it 'assigns the current_store id' do - expect(controller.simple_current_order.store_id).to eq store.id + Spree::Deprecation.silence do + expect(controller.simple_current_order.store_id).to eq store.id + end + end + it 'is deprecated' do + Spree::Deprecation.silence do + expect(Spree::Deprecation).to(receive(:warn)) + controller.simple_current_order + end end end diff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rb index 61446f1b355..6dfa12b2bf1 100644 --- a/frontend/app/controllers/spree/store_controller.rb +++ b/frontend/app/controllers/spree/store_controller.rb @@ -11,7 +11,7 @@ def unauthorized def cart_link render partial: 'spree/shared/link_to_cart' - fresh_when(simple_current_order, template: 'spree/shared/_link_to_cart') + fresh_when(current_order, template: 'spree/shared/_link_to_cart') end private