-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from mvz/fix-order-association-2-4
Fix order association (2-4-stable)
- Loading branch information
Showing
4 changed files
with
78 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,35 @@ | |
spree_post :create, { spree_user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } } | ||
expect(response).to redirect_to spree.root_path(thing: 7) | ||
end | ||
|
||
context 'with a guest token present' do | ||
before do | ||
request.cookie_jar.signed[:guest_token] = 'ABC' | ||
end | ||
|
||
it 'assigns orders with the correct token and no user present' do | ||
order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil) | ||
spree_post :create, spree_user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } | ||
user = Spree::User.find_by_email('[email protected]') | ||
|
||
order.reload | ||
expect(order.user_id).to eq user.id | ||
expect(order.created_by_id).to eq user.id | ||
end | ||
|
||
it 'does not assign orders with an existing user' do | ||
order = create(:order, guest_token: 'ABC', user_id: 200) | ||
spree_post :create, spree_user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } | ||
|
||
expect(order.reload.user_id).to eq 200 | ||
end | ||
|
||
it 'does not assign orders with a different token' do | ||
order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil) | ||
spree_post :create, spree_user: { email: '[email protected]', password: 'foobar123', password_confirmation: 'foobar123' } | ||
|
||
expect(order.reload.user_id).to be_nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters