spree_auth_devise 4.1.0 → 4.3.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of spree_auth_devise might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gem_release.yml +2 -0
- data/.travis.yml +32 -23
- data/Appraisals +1 -1
- data/Gemfile +1 -0
- data/Rakefile +9 -3
- data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
- data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
- data/app/controllers/spree/user_confirmations_controller.rb +22 -0
- data/app/controllers/spree/user_passwords_controller.rb +15 -1
- data/app/controllers/spree/user_registrations_controller.rb +15 -0
- data/app/controllers/spree/user_sessions_controller.rb +8 -0
- data/app/mailers/spree/user_mailer.rb +11 -4
- data/app/models/spree/user.rb +46 -0
- data/app/services/spree/account/create.rb +19 -0
- data/app/services/spree/account/update.rb +17 -0
- data/app/views/spree/user_mailer/confirmation_instructions.html.erb +20 -0
- data/app/views/spree/user_mailer/confirmation_instructions.text.erb +8 -5
- data/app/views/spree/user_mailer/reset_password_instructions.html.erb +20 -0
- data/app/views/spree/user_mailer/reset_password_instructions.text.erb +7 -5
- data/config/initializers/warden.rb +1 -1
- data/config/locales/de.yml +16 -0
- data/config/locales/en.yml +18 -5
- data/config/locales/zh-TW.yml +58 -0
- data/config/routes.rb +13 -1
- data/gemfiles/spree_4_1.gemfile +1 -1
- data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
- data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +16 -0
- data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +2 -1
- data/lib/spree/auth/engine.rb +15 -10
- data/lib/spree/auth/version.rb +9 -0
- data/lib/spree_auth_devise.rb +0 -1
- data/lib/views/backend/spree/admin/user_sessions/new.html.erb +1 -1
- data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
- data/spec/features/admin/sign_in_spec.rb +10 -3
- data/spec/features/checkout_spec.rb +3 -3
- data/spec/features/confirmation_spec.rb +2 -5
- data/spec/features/sign_in_spec.rb +15 -8
- data/spec/features/sign_out_spec.rb +1 -3
- data/spec/mailers/user_mailer_spec.rb +3 -3
- data/spec/models/user_spec.rb +43 -10
- data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
- data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
- data/spec/spec_helper.rb +7 -38
- data/spec/support/confirm_helpers.rb +21 -8
- data/spree_auth_devise.gemspec +16 -29
- metadata +32 -362
- data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +0 -4
- data/spec/support/add_to_cart.rb +0 -22
- data/spec/support/authentication_helpers.rb +0 -14
- data/spec/support/cache_helpers.rb +0 -5
- data/spec/support/capybara.rb +0 -23
- data/spec/support/database_cleaner.rb +0 -17
- data/spec/support/factory_girl.rb +0 -5
- data/spec/support/spree.rb +0 -10
- data/spec/support/user_helper.rb +0 -11
@@ -33,9 +33,16 @@ RSpec.feature 'Admin - Sign In', type: :feature do
|
|
33
33
|
|
34
34
|
fill_in 'Email', with: user.email
|
35
35
|
fill_in 'Password', with: 'secret'
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if Spree.version.to_f > 4.1
|
37
|
+
click_button 'Login'
|
38
|
+
within '.navbar .dropdown-menu' do
|
39
|
+
expect(page).to have_text 'admin@person.com'
|
40
|
+
end
|
41
|
+
else
|
42
|
+
click_button 'Log in'
|
43
|
+
within '.user-menu' do
|
44
|
+
expect(page).to have_text 'admin@person.com'
|
45
|
+
end
|
39
46
|
end
|
40
47
|
expect(current_path).to eq '/admin/orders'
|
41
48
|
end
|
@@ -60,7 +60,7 @@ RSpec.feature 'Checkout', :js, type: :feature do
|
|
60
60
|
find('a.cart-icon').click
|
61
61
|
|
62
62
|
expect(page).to have_text 'RoR Mug'
|
63
|
-
within('h1') { expect(page).to have_text 'YOUR SHOPPING
|
63
|
+
within('h1') { expect(page).to have_text 'YOUR SHOPPING CART' }
|
64
64
|
|
65
65
|
click_link 'checkout'
|
66
66
|
|
@@ -87,9 +87,9 @@ RSpec.feature 'Checkout', :js, type: :feature do
|
|
87
87
|
# The 'plain-text' version is sent in the email and there's one way to get that!
|
88
88
|
reset_password_email = ActionMailer::Base.deliveries.first
|
89
89
|
token_url_regex = /^http:\/\/www.example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
|
90
|
-
token = token_url_regex.match(reset_password_email.body.
|
90
|
+
token = token_url_regex.match(reset_password_email.body.encoded)[1]
|
91
91
|
|
92
|
-
visit spree.edit_spree_user_password_path(reset_password_token: token)
|
92
|
+
visit spree.edit_spree_user_password_path(reset_password_token: token.strip).tr("%0D","")
|
93
93
|
fill_in 'Password', with: 'password'
|
94
94
|
fill_in 'Password Confirmation', with: 'password'
|
95
95
|
click_button 'Update'
|
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
RSpec.feature 'Confirmation', type: :feature,
|
3
|
+
RSpec.feature 'Confirmation', type: :feature, confirmable: true do
|
4
4
|
before do
|
5
|
-
|
6
|
-
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
|
5
|
+
expect(Spree::UserMailer).to receive(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
|
7
6
|
end
|
8
7
|
|
9
|
-
after(:each) { set_confirmable_option(false) }
|
10
|
-
|
11
8
|
background do
|
12
9
|
ActionMailer::Base.default_url_options[:host] = 'http://example.com'
|
13
10
|
end
|
@@ -33,19 +33,26 @@ RSpec.feature 'Sign In', type: :feature do
|
|
33
33
|
|
34
34
|
fill_in 'Email', with: user.email
|
35
35
|
fill_in 'Password', with: user.password
|
36
|
-
click_button 'Log in'
|
37
36
|
|
38
|
-
|
39
|
-
|
37
|
+
if Spree.version.to_f > 4.1
|
38
|
+
click_button 'Login'
|
39
|
+
within '.navbar .dropdown-menu' do
|
40
|
+
expect(page).to have_text 'admin@person.com'
|
41
|
+
end
|
42
|
+
else
|
43
|
+
click_button 'Log in'
|
44
|
+
within '.user-menu' do
|
45
|
+
expect(page).to have_text 'admin@person.com'
|
46
|
+
end
|
40
47
|
end
|
41
48
|
expect(current_path).to eq '/admin/orders'
|
42
49
|
end
|
43
50
|
|
44
|
-
|
51
|
+
it 'should store the user previous location' do
|
45
52
|
visit spree.account_path
|
46
|
-
fill_in
|
47
|
-
fill_in
|
48
|
-
click_button
|
49
|
-
expect(current_path).to eq
|
53
|
+
fill_in 'Email', with: @user.email
|
54
|
+
fill_in 'Password', with: @user.password
|
55
|
+
click_button 'Log in'
|
56
|
+
expect(current_path).to eq '/account'
|
50
57
|
end
|
51
58
|
end
|
@@ -5,7 +5,7 @@ RSpec.describe Spree::UserMailer, type: :mailer do
|
|
5
5
|
describe '#reset_password_instructions' do
|
6
6
|
describe 'message contents' do
|
7
7
|
before do
|
8
|
-
@message = described_class.reset_password_instructions(user, 'token goes here')
|
8
|
+
@message = described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id })
|
9
9
|
end
|
10
10
|
|
11
11
|
context 'subject includes' do
|
@@ -22,7 +22,7 @@ RSpec.describe Spree::UserMailer, type: :mailer do
|
|
22
22
|
|
23
23
|
context 'body includes' do
|
24
24
|
it 'password reset url' do
|
25
|
-
expect(@message.body.
|
25
|
+
expect(@message.body.encoded).to include "http://#{store.url}/user/spree_user/password/edit"
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -30,7 +30,7 @@ RSpec.describe Spree::UserMailer, type: :mailer do
|
|
30
30
|
describe 'legacy support for User object' do
|
31
31
|
it 'sends an email' do
|
32
32
|
expect {
|
33
|
-
described_class.reset_password_instructions(user, 'token goes here').deliver_now
|
33
|
+
described_class.reset_password_instructions(user, 'token goes here', { current_store_id: Spree::Store.current.id }).deliver_now
|
34
34
|
}.to change(ActionMailer::Base.deliveries, :size).by(1)
|
35
35
|
end
|
36
36
|
end
|
data/spec/models/user_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
RSpec.describe Spree::User, type: :model do
|
2
2
|
before(:all) { Spree::Role.create name: 'admin' }
|
3
|
+
let!(:store) { create(:store) }
|
3
4
|
|
4
5
|
it '#admin?' do
|
5
6
|
expect(create(:admin_user).admin?).to be true
|
@@ -8,8 +9,9 @@ RSpec.describe Spree::User, type: :model do
|
|
8
9
|
|
9
10
|
it 'generates the reset password token' do
|
10
11
|
user = build(:user)
|
11
|
-
|
12
|
-
user.
|
12
|
+
current_store = Spree::Store.current
|
13
|
+
expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, { current_store_id: current_store.id }).and_return(double(deliver: true))
|
14
|
+
user.send_reset_password_instructions(current_store)
|
13
15
|
expect(user.reset_password_token).not_to be_nil
|
14
16
|
end
|
15
17
|
|
@@ -63,17 +65,48 @@ RSpec.describe Spree::User, type: :model do
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
66
|
-
describe "confirmable"
|
67
|
-
it "is confirmable if the confirmable option is enabled" do
|
68
|
-
|
69
|
-
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
|
68
|
+
describe "confirmable" do
|
69
|
+
it "is confirmable if the confirmable option is enabled", confirmable: true do
|
70
|
+
Spree::UserMailer.stub(:confirmation_instructions).with(anything, anything, { current_store_id: Spree::Store.current.id }).and_return(double(deliver: true))
|
70
71
|
expect(Spree.user_class.devise_modules).to include(:confirmable)
|
71
|
-
set_confirmable_option(false)
|
72
72
|
end
|
73
73
|
|
74
|
-
it "is not confirmable if the confirmable option is disabled" do
|
75
|
-
|
76
|
-
|
74
|
+
it "is not confirmable if the confirmable option is disabled", confirmable: false do
|
75
|
+
expect(Spree.user_class.devise_modules).not_to include(:confirmable)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#send_confirmation_instructions", retry: 2 do
|
80
|
+
let(:default_store) { Spree::Store.default }
|
81
|
+
|
82
|
+
context "when current store not exists" do
|
83
|
+
it 'takes default store and sends confirmation instruction', confirmable: true do
|
84
|
+
user = Spree.user_class.new
|
85
|
+
user.email = FFaker::Internet.email
|
86
|
+
user.password = user.password_confirmation = 'pass1234'
|
87
|
+
user.save
|
88
|
+
|
89
|
+
expect(Spree::UserMailer).to receive(:confirmation_instructions).with(
|
90
|
+
user, anything, { current_store_id: default_store.id }).and_return(double(deliver: true)
|
91
|
+
)
|
92
|
+
|
93
|
+
user.send_confirmation_instructions(nil)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "when current store exists" do
|
98
|
+
it 'takes current store and sends confirmation instruction', confirmable: true do
|
99
|
+
user = Spree.user_class.new
|
100
|
+
user.email = FFaker::Internet.email
|
101
|
+
user.password = user.password_confirmation = 'pass1234'
|
102
|
+
user.save
|
103
|
+
|
104
|
+
expect(Spree::UserMailer).to receive(:confirmation_instructions).with(
|
105
|
+
user, anything, { current_store_id: store.id }).and_return(double(deliver: true)
|
106
|
+
)
|
107
|
+
|
108
|
+
user.send_confirmation_instructions(store)
|
109
|
+
end
|
77
110
|
end
|
78
111
|
end
|
79
112
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Storefront API v2 Account Confirmation spec', type: :request do
|
4
|
+
describe 'account_confirmations#show' do
|
5
|
+
|
6
|
+
before do
|
7
|
+
Spree::User.stub(:confirm_by_token, confirmation_token: confirmation_token).and_return user
|
8
|
+
get "/api/v2/storefront/account_confirmations/#{confirmation_token}"
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'valid confirmation_token param' do
|
12
|
+
let(:user) { create(:user, confirmation_token: '12345') }
|
13
|
+
let(:confirmation_token) { user.confirmation_token }
|
14
|
+
|
15
|
+
it_behaves_like 'returns 200 HTTP status'
|
16
|
+
|
17
|
+
it 'returns user state' do
|
18
|
+
expect(JSON.parse(response.body)['data']['state']).to eq('')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'invalid confirmation_token param' do
|
23
|
+
let(:user) do
|
24
|
+
user = create(:user)
|
25
|
+
user.errors.add(:confirmation_token, :invalid)
|
26
|
+
return user
|
27
|
+
end
|
28
|
+
let(:confirmation_token) { 'dummy_token' }
|
29
|
+
|
30
|
+
it 'return 422 status' do
|
31
|
+
expect(response.code).to eq('422')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'return JSON API payload of error' do
|
35
|
+
expect(JSON.parse(response.body)['error']).to eq("Confirmation token is invalid")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'blank confirmation_token param' do
|
40
|
+
let(:user) { build(:user) }
|
41
|
+
let(:confirmation_token) { '' }
|
42
|
+
|
43
|
+
it 'return 301 status' do
|
44
|
+
expect(response.code).to eq('301')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Storefront API v2 Account spec', type: :request do
|
4
|
+
describe 'account#create' do
|
5
|
+
before { post '/api/v2/storefront/account', params: params }
|
6
|
+
|
7
|
+
context 'valid user params' do
|
8
|
+
let(:params) do
|
9
|
+
{
|
10
|
+
"user": {
|
11
|
+
"email": "hello@example.com",
|
12
|
+
"password": "password123",
|
13
|
+
"password_confirmation": "password123"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
it_behaves_like 'returns 200 HTTP status'
|
19
|
+
|
20
|
+
it 'return JSON API payload of User' do
|
21
|
+
expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('hello@example.com')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'invalid user params' do
|
26
|
+
let(:params) do
|
27
|
+
{
|
28
|
+
"user": {
|
29
|
+
"email": "hello@example.com",
|
30
|
+
"password": "password123",
|
31
|
+
"password_confirmation": ""
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'return JSON API payload of error' do
|
37
|
+
expect(JSON.parse(response.body)['error']).to eq("Password Confirmation doesn't match Password")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'account#update' do
|
44
|
+
include_context 'API v2 tokens'
|
45
|
+
|
46
|
+
let!(:user) { create(:user_with_addresses) }
|
47
|
+
let(:headers) { headers_bearer }
|
48
|
+
|
49
|
+
before { patch '/api/v2/storefront/account', params: params, headers: headers }
|
50
|
+
|
51
|
+
context 'valid user params' do
|
52
|
+
let(:params) do
|
53
|
+
{
|
54
|
+
"user": {
|
55
|
+
"email": "spree@example.com",
|
56
|
+
"password": "password123",
|
57
|
+
"password_confirmation": "password123"
|
58
|
+
}
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
it_behaves_like 'returns 200 HTTP status'
|
63
|
+
|
64
|
+
it 'return JSON API payload of User' do
|
65
|
+
expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('spree@example.com')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'valid user params without passwords' do
|
70
|
+
let(:params) do
|
71
|
+
{
|
72
|
+
"user": {
|
73
|
+
"email": "spree@example.com"
|
74
|
+
}
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it_behaves_like 'returns 200 HTTP status'
|
79
|
+
|
80
|
+
it 'return JSON API payload of User' do
|
81
|
+
expect(JSON.parse(response.body)['data']['attributes']['email']).to eq('spree@example.com')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'invalid user params' do
|
86
|
+
let(:params) do
|
87
|
+
{
|
88
|
+
"user": {
|
89
|
+
"email": "spree@example.com",
|
90
|
+
"password": "password123",
|
91
|
+
"password_confirmation": ""
|
92
|
+
}
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'return JSON API payload of error' do
|
97
|
+
expect(JSON.parse(response.body)['error']).to eq("Password Confirmation doesn't match Password")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,49 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Configure Rails Environment
|
2
|
+
ENV['RAILS_ENV'] = 'test'
|
3
3
|
|
4
|
-
|
4
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
5
5
|
|
6
|
-
require
|
6
|
+
require 'spree_dev_tools/rspec/spec_helper'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
require 'pry'
|
12
|
-
|
13
|
-
require 'spree/testing_support/auth_helpers'
|
14
|
-
require 'spree/testing_support/checkout_helpers'
|
15
|
-
|
16
|
-
require 'spree/testing_support/authorization_helpers'
|
17
|
-
require 'spree/testing_support/capybara_ext'
|
18
|
-
require 'spree/testing_support/controller_requests'
|
19
|
-
require 'spree/testing_support/factories'
|
20
|
-
require 'spree/testing_support/url_helpers'
|
8
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
9
|
+
# in spec/support/ and its subdirectories.
|
10
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].sort.each { |f| require f }
|
21
11
|
|
22
12
|
RSpec.configure do |config|
|
23
|
-
config.filter_run focus: true
|
24
|
-
config.infer_spec_type_from_file_location!
|
25
|
-
config.raise_errors_for_deprecations!
|
26
|
-
config.run_all_when_everything_filtered = true
|
27
|
-
config.use_transactional_fixtures = false
|
28
|
-
|
29
|
-
config.mock_with :rspec do |mock|
|
30
|
-
mock.syntax = [:should, :expect]
|
31
|
-
end
|
32
|
-
|
33
|
-
config.order = :random
|
34
|
-
Kernel.srand(config.seed)
|
35
|
-
|
36
13
|
config.before(:each) do
|
37
14
|
allow(RSpec::Rails::ViewRendering::EmptyTemplateHandler)
|
38
15
|
.to receive(:call)
|
39
16
|
.and_return(%("")) if Rails.gem_version >= Gem::Version.new('6.0.0.beta1')
|
40
|
-
|
41
|
-
create(:store)
|
42
17
|
end
|
43
|
-
|
44
|
-
config.include Spree::TestingSupport::AuthHelpers, type: :feature
|
45
|
-
config.include Spree::TestingSupport::CheckoutHelpers, type: :feature
|
46
|
-
config.include Spree::TestingSupport::UrlHelpers
|
47
18
|
end
|
48
|
-
|
49
|
-
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
@@ -1,11 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.around do |example|
|
3
|
+
if example.metadata.key?(:confirmable)
|
4
|
+
old_user = Spree::User
|
5
|
+
|
6
|
+
begin
|
7
|
+
example.run
|
8
|
+
ensure
|
9
|
+
Spree.const_set('User', old_user)
|
10
|
+
end
|
11
|
+
else
|
12
|
+
example.run
|
13
|
+
end
|
6
14
|
end
|
7
|
-
end
|
8
15
|
|
9
|
-
|
10
|
-
|
16
|
+
config.before do |example|
|
17
|
+
if example.metadata.key?(:confirmable)
|
18
|
+
Spree::Auth::Config[:confirmable] = example.metadata[:confirmable]
|
19
|
+
|
20
|
+
Spree.send(:remove_const, :User)
|
21
|
+
load File.expand_path('../../../app/models/spree/user.rb', __FILE__)
|
22
|
+
end
|
23
|
+
end
|
11
24
|
end
|