Skip to content

Commit

Permalink
Merge pull request #1386 from CasperSleep/scope_set_current_order_by_…
Browse files Browse the repository at this point in the history
…store

set_current_order should scope by store when merging orders
  • Loading branch information
jhawthorn authored Aug 15, 2016
2 parents 5aa44df + be79cb9 commit ad7a2fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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 @@ -59,7 +59,7 @@ def associate_user

def set_current_order
if try_spree_current_user && current_order
try_spree_current_user.orders.incomplete.where('id != ?', current_order.id).each do |order|
try_spree_current_user.orders.by_store(current_store).incomplete.where('id != ?', current_order.id).each do |order|
current_order.merge!(order, try_spree_current_user)
end
end
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 @@ -66,14 +66,26 @@ class FakesController < ApplicationController
end

describe '#set_current_order' do
let(:incomplete_order) { create(:order, user: user) }
let(:incomplete_order) { create(:order, store: incomplete_order_store, user: user) }

context 'when current order not equal to users incomplete orders' do
before { allow(controller).to receive_messages(current_order: order, last_incomplete_order: incomplete_order, cookies: double(signed: { guest_token: 'guest_token' })) }

it 'calls Spree::Order#merge! method' do
expect(order).to receive(:merge!).with(incomplete_order, user)
controller.set_current_order
context "an order from another store" do
let(:incomplete_order_store) { create(:store) }

it 'doesnt call Spree::Order#merge! method' do
expect(order).to_not receive(:merge!)
controller.set_current_order
end
end
context "an order from the same store" do
let(:incomplete_order_store) { store }

it 'calls Spree::Order#merge! method' do
expect(order).to receive(:merge!).with(incomplete_order, user)
controller.set_current_order
end
end
end
end
Expand Down

0 comments on commit ad7a2fb

Please sign in to comment.