Skip to content

Commit

Permalink
Fix user unloading in confirmation related specs
Browse files Browse the repository at this point in the history
  • Loading branch information
artplan1 committed Feb 16, 2018
1 parent c007ce6 commit c511d20
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions config/initializers/warden.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Merges users orders to their account after sign in and sign up.
Warden::Manager.after_set_user except: :fetch do |user, auth, _opts|
if auth.cookies.signed[:guest_token].present?
if user.is_a?(Spree::User)
Spree::Order.incomplete.where(guest_token: auth.cookies.signed[:guest_token], user_id: nil).each do |order|
order.associate_user!(user)
end
guest_token = auth.cookies.signed[:guest_token]

if guest_token.present? && user.is_a?(Spree::User)
Spree::Order.incomplete.where(guest_token: guest_token, user_id: nil).each do |order|
order.associate_user!(user)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/features/confirmation_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

feature 'Confirmation' do
RSpec.feature 'Confirmation', type: :feature, reload_user: true do
before do
set_confirmable_option(true)
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
end
end

describe "confirmable" do
describe "confirmable", reload_user: true do
it "is confirmable if the confirmable option is enabled" do
set_confirmable_option(true)
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
Expand Down
11 changes: 11 additions & 0 deletions spec/support/user_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RSpec.configure do |config|
# allows to keep user const after reload
config.around :each, :reload_user do |example|
old_user = Spree::User

example.run

Spree.send(:remove_const, 'User')
Spree.const_set('User', old_user)
end
end

0 comments on commit c511d20

Please sign in to comment.