Skip to content

Commit

Permalink
Assign store id to each order.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Dutil authored and Jeff Dutil committed Oct 9, 2014
1 parent 6a5f22c commit 15df7e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/db/migrate/20141009204607_add_store_id_to_orders.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class AddStoreIdToOrders < ActiveRecord::Migration
def change
add_column :spree_orders, :store_id, :integer
if Spree::Store.default.persisted?
Spree::Order.where(store_id: nil).update_all(store_id: Spree::Store.default.id)
end
end
end
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 @@ -79,7 +79,7 @@ def last_incomplete_order
end

def current_order_params
{ currency: current_currency, guest_token: cookies.signed[:guest_token], user_id: try_spree_current_user.try(:id) }
{ currency: current_currency, guest_token: cookies.signed[:guest_token], store_id: current_store.id, user_id: try_spree_current_user.try(:id) }
end

def find_order_by_token_or_user(options={}, with_adjustments = false)
Expand Down
9 changes: 9 additions & 0 deletions core/spec/lib/spree/core/controller_helpers/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class FakesController < ApplicationController

let(:user) { create(:user) }
let(:order) { create(:order, user: user) }
let(:store) { create(:store) }

describe '#simple_current_order' do
before { controller.stub(try_spree_current_user: user) }
Expand All @@ -24,6 +25,7 @@ class FakesController < ApplicationController
describe '#current_order' do
before {
Spree::Order.destroy_all # TODO data is leaking between specs as database_cleaner or rspec 3 was broken in Rails 4.1.6 & 4.0.10
controller.stub(current_store: store)
controller.stub(try_spree_current_user: user)
}
context 'create_order_if_necessary option is false' do
Expand All @@ -38,6 +40,11 @@ class FakesController < ApplicationController
controller.current_order(create_order_if_necessary: true)
}.to change(Spree::Order, :count).to(1)
end

it 'assigns the current_store id' do
controller.current_order(create_order_if_necessary: true)
expect(Spree::Order.last.store_id).to eq store.id
end
end
end

Expand All @@ -63,13 +70,15 @@ class FakesController < ApplicationController
describe '#set_current_order' do
let(:incomplete_order) { create(:order) }
before { controller.stub(try_spree_current_user: user) }

context 'when logged in user' do
before { controller.stub(last_incomplete_order: incomplete_order) }
it 'sends guest_token cookie to user' do
controller.set_current_order
expect(cookies.permanent.signed[:guest_token]).to eq incomplete_order.guest_token
end
end

context 'when current order not equal last imcomplete order' do
before { controller.stub(current_order: order, last_incomplete_order: incomplete_order, cookies: double(signed: { guest_token: 'guest_token' })) }
it 'calls Spree::Order#merge! method' do
Expand Down

0 comments on commit 15df7e7

Please sign in to comment.