forked from solidusio/solidus_auth_devise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests for Devise's :confirmable module
The `set_confirmable_options` helper was fundamentally broken: the code being tested is only loaded once, so simply changing values in Spree::Auth::Config does not have any effect on the modules loaded in Spree::User. The only way to ensure we load the right modules is removing and reloading the Spree::User class after stubbing the configuration.
- Loading branch information
1 parent
03d16cf
commit 64f9120
Showing
3 changed files
with
25 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
|
||
require 'spec_helper' | ||
|
||
feature 'Confirmation' do | ||
RSpec.feature 'Confirmation' do | ||
before do | ||
set_confirmable_option(false) | ||
allow(Spree::UserMailer).to receive(:confirmation_instructions) | ||
.and_return(double(deliver: true)) | ||
end | ||
|
@@ -15,7 +14,7 @@ | |
ActionMailer::Base.default_url_options[:host] = 'http://example.com' | ||
end | ||
|
||
scenario 'create a new user', :js do | ||
scenario 'create a new user', js: true, confirmable: false do | ||
visit spree.signup_path | ||
|
||
fill_in 'Email', with: '[email protected]' | ||
|
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 |
---|---|---|
@@ -1,17 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module ConfirmHelpers | ||
def set_confirmable_option(value) | ||
if value | ||
Spree::User.devise_modules.push(:confirmable) | ||
stub_spree_preferences(Spree::Auth::Config, confirmable: true) | ||
RSpec.configure do |config| | ||
config.around do |example| | ||
if example.metadata.key?(:confirmable) | ||
old_user = Spree::User | ||
|
||
begin | ||
example.run | ||
ensure | ||
Spree.const_set('User', old_user) | ||
end | ||
else | ||
Spree::User.devise_modules.delete(:confirmable) | ||
stub_spree_preferences(Spree::Auth::Config, confirmable: false) | ||
example.run | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |c| | ||
c.include ConfirmHelpers | ||
config.before do |example| | ||
if example.metadata.key?(:confirmable) | ||
stub_spree_preferences(Spree::Auth::Config, confirmable: example.metadata[:confirmable]) | ||
|
||
Spree.send(:remove_const, :User) | ||
load File.expand_path('../../../app/models/spree/user.rb', __FILE__) | ||
end | ||
end | ||
end |