Skip to content

Commit

Permalink
Deprecate simple_current_order
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ericsaupe committed May 22, 2017
1 parent dc5d60b commit 26d81b2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
4 changes: 2 additions & 2 deletions core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}) <span class='amount'>#{simple_current_order.display_total.to_html}</span>"
text = "#{text}: (#{current_order.item_count}) <span class='amount'>#{current_order.display_total.to_html}</span>"
css_class = 'full'
end

Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/core/controller_helpers/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {})
Expand Down
20 changes: 16 additions & 4 deletions core/spec/lib/spree/core/controller_helpers/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/controllers/spree/store_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26d81b2

Please sign in to comment.