spree_auth_devise 4.1.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -23
  3. data/Appraisals +1 -1
  4. data/Rakefile +9 -3
  5. data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
  6. data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
  7. data/app/controllers/spree/user_passwords_controller.rb +1 -1
  8. data/app/mailers/spree/user_mailer.rb +6 -2
  9. data/app/models/spree/user.rb +17 -0
  10. data/app/services/spree/account/create.rb +19 -0
  11. data/app/services/spree/account/update.rb +17 -0
  12. data/app/views/spree/user_mailer/confirmation_instructions.text.erb +3 -3
  13. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +2 -7
  14. data/config/locales/de.yml +18 -0
  15. data/config/locales/en.yml +7 -2
  16. data/config/locales/zh-TW.yml +60 -0
  17. data/config/routes.rb +10 -0
  18. data/gemfiles/spree_4_1.gemfile +1 -1
  19. data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
  20. data/lib/spree/auth/engine.rb +14 -1
  21. data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
  22. data/spec/features/admin/sign_in_spec.rb +8 -2
  23. data/spec/features/checkout_spec.rb +1 -1
  24. data/spec/features/sign_in_spec.rb +13 -7
  25. data/spec/features/sign_out_spec.rb +1 -3
  26. data/spec/mailers/user_mailer_spec.rb +2 -2
  27. data/spec/models/user_spec.rb +4 -2
  28. data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
  29. data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
  30. data/spec/spec_helper.rb +7 -38
  31. data/spree_auth_devise.gemspec +3 -25
  32. metadata +21 -343
  33. data/spec/support/add_to_cart.rb +0 -22
  34. data/spec/support/authentication_helpers.rb +0 -14
  35. data/spec/support/cache_helpers.rb +0 -5
  36. data/spec/support/capybara.rb +0 -23
  37. data/spec/support/database_cleaner.rb +0 -17
  38. data/spec/support/factory_girl.rb +0 -5
  39. data/spec/support/spree.rb +0 -10
@@ -42,7 +42,12 @@ module Spree
42
42
  'lib/assets/javascripts/spree/frontend/spree_auth.js',
43
43
  'lib/assets/javascripts/spree/frontend/spree_auth.css'
44
44
  ]
45
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
45
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/**/*_decorator*.rb")) do |c|
46
+ Rails.configuration.cache_classes ? require(c) : load(c)
47
+ end
48
+ end
49
+ if Spree::Auth::Engine.api_available?
50
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/api/**/*_decorator*.rb")) do |c|
46
51
  Rails.configuration.cache_classes ? require(c) : load(c)
47
52
  end
48
53
  end
@@ -61,6 +66,10 @@ module Spree
61
66
  @@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Frontend::Engine')
62
67
  end
63
68
 
69
+ def self.api_available?
70
+ @@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Api::Engine')
71
+ end
72
+
64
73
  if backend_available?
65
74
  paths["app/controllers"] << "lib/controllers/backend"
66
75
  paths["app/views"] << "lib/views/backend"
@@ -71,6 +80,10 @@ module Spree
71
80
  paths["app/views"] << "lib/views/frontend"
72
81
  end
73
82
 
83
+ if api_available?
84
+ paths["app/controllers"] << "lib/controllers/api"
85
+ end
86
+
74
87
  config.to_prepare &method(:activate).to_proc
75
88
  end
76
89
  end
@@ -0,0 +1,63 @@
1
+ RSpec.describe Spree::Api::V2::Storefront::PasswordsController, type: :controller do
2
+ let(:user) { create(:user) }
3
+ let(:password) { 'new_password' }
4
+ let(:store) { create(:store) }
5
+
6
+ describe 'POST create' do
7
+ before { post :create, params: params }
8
+
9
+ context 'when the user email has not been specified' do
10
+ let(:params) { { user: { email: '' } } }
11
+ it 'responds with not found status' do
12
+ expect(response.code).to eq('404')
13
+ end
14
+ end
15
+
16
+ context 'when the user email not found' do
17
+ let(:params) { { user: { email: 'dummy_email@example.com' } } }
18
+ it 'responds with not found status' do
19
+ expect(response.code).to eq('404')
20
+ end
21
+ end
22
+
23
+ context 'when the user email has been specified' do
24
+ let(:params) { { user: { email: user.email } } }
25
+ it_behaves_like 'returns 200 HTTP status'
26
+ end
27
+ end
28
+
29
+ describe 'PATCH update' do
30
+ before { patch :update, params: params }
31
+
32
+ context 'when updating password with blank password' do
33
+ let(:params) {
34
+ {
35
+ id: user.send_reset_password_instructions(Spree::Store.current),
36
+ user: {
37
+ password: '',
38
+ password_confirmation: ''
39
+ }
40
+ }
41
+ }
42
+
43
+ it 'responds with error' do
44
+ expect(response.code).to eq('422')
45
+ expect(JSON.parse(response.body)['error']).to eq("Password can't be blank")
46
+ end
47
+ end
48
+
49
+ context 'when updating password with specified password' do
50
+ let(:params) {
51
+ {
52
+ id: user.send_reset_password_instructions(Spree::Store.current),
53
+ user: {
54
+ password: password,
55
+ password_confirmation: password
56
+ }
57
+ }
58
+ }
59
+
60
+ it_behaves_like 'returns 200 HTTP status'
61
+ end
62
+ end
63
+ end
@@ -34,8 +34,14 @@ RSpec.feature 'Admin - Sign In', type: :feature do
34
34
  fill_in 'Email', with: user.email
35
35
  fill_in 'Password', with: 'secret'
36
36
  click_button 'Log in'
37
- within '.user-menu' do
38
- expect(page).to have_text 'admin@person.com'
37
+ if Spree.version.to_f > 4.1
38
+ within '.navbar .dropdown-menu' do
39
+ expect(page).to have_text 'admin@person.com'
40
+ end
41
+ else
42
+ within '.user-menu' do
43
+ expect(page).to have_text 'admin@person.com'
44
+ end
39
45
  end
40
46
  expect(current_path).to eq '/admin/orders'
41
47
  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 BAG' }
63
+ within('h1') { expect(page).to have_text 'YOUR SHOPPING CART' }
64
64
 
65
65
  click_link 'checkout'
66
66
 
@@ -35,17 +35,23 @@ RSpec.feature 'Sign In', type: :feature do
35
35
  fill_in 'Password', with: user.password
36
36
  click_button 'Log in'
37
37
 
38
- within '.user-menu' do
39
- expect(page).to have_text 'admin@person.com'
38
+ if Spree.version.to_f > 4.1
39
+ within '.navbar .dropdown-menu' do
40
+ expect(page).to have_text 'admin@person.com'
41
+ end
42
+ else
43
+ within '.user-menu' do
44
+ expect(page).to have_text 'admin@person.com'
45
+ end
40
46
  end
41
47
  expect(current_path).to eq '/admin/orders'
42
48
  end
43
49
 
44
- xit "should store the user previous location" do
50
+ it 'should store the user previous location' do
45
51
  visit spree.account_path
46
- fill_in "Email", with: @user.email
47
- fill_in "Password", with: @user.password
48
- click_button "Login"
49
- expect(current_path).to eq "/account"
52
+ fill_in 'Email', with: @user.email
53
+ fill_in 'Password', with: @user.password
54
+ click_button 'Log in'
55
+ expect(current_path).to eq '/account'
50
56
  end
51
57
  end
@@ -26,9 +26,7 @@ RSpec.feature 'Sign Out', type: :feature, js: true do
26
26
  let!(:other_user) { create(:user) }
27
27
 
28
28
  it 'clears token cookies' do
29
- add_to_cart(mug) do
30
- find('.close').click
31
- end
29
+ add_to_cart(mug)
32
30
 
33
31
  log_out
34
32
 
@@ -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
@@ -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
@@ -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
- expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
12
- user.send_reset_password_instructions
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
 
@@ -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
@@ -1,49 +1,18 @@
1
- require 'simplecov'
2
- SimpleCov.start 'rails'
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
3
 
4
- ENV['RAILS_ENV'] ||= 'test'
4
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
5
5
 
6
- require File.expand_path('../dummy/config/environment', __FILE__)
6
+ require 'spree_dev_tools/rspec/spec_helper'
7
7
 
8
- require 'rspec/rails'
9
- require 'shoulda-matchers'
10
- require 'ffaker'
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 }
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.name = 'spree_auth_devise'
6
- s.version = '4.1.0'
6
+ s.version = '4.2.0'
7
7
  s.summary = 'Provides authentication and authorization services for use with Spree by using Devise and CanCan.'
8
8
  s.description = s.summary
9
9
 
@@ -24,31 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency 'devise', '~> 4.7'
25
25
  s.add_dependency 'devise-encryptable', '0.2.0'
26
26
 
27
- spree_version = '>= 4.1.0.alpha', '< 5.0'
27
+ spree_version = '>= 4.1', '< 5.0'
28
28
  s.add_dependency 'spree_core', spree_version
29
29
  s.add_dependency 'spree_extension'
30
30
 
31
- s.add_development_dependency 'appraisal'
32
- s.add_development_dependency 'capybara'
33
- s.add_development_dependency 'capybara-screenshot'
34
- s.add_development_dependency 'coffee-rails', '~> 4.2'
35
- s.add_development_dependency 'database_cleaner', '~> 1.5'
36
- s.add_development_dependency 'email_spec', '~> 2.1'
37
- s.add_development_dependency 'factory_bot', '~> 4.7'
38
- s.add_development_dependency 'ffaker'
39
- s.add_development_dependency 'launchy'
40
- s.add_development_dependency 'mysql2'
41
- s.add_development_dependency 'pg'
42
- s.add_development_dependency 'pry'
43
- s.add_development_dependency 'puma'
44
- s.add_development_dependency 'rails-controller-testing'
45
- s.add_development_dependency 'rspec-rails', '~> 4.0.0.beta2'
46
- s.add_development_dependency 'sass-rails'
47
- s.add_development_dependency 'selenium-webdriver'
48
- s.add_development_dependency 'shoulda-matchers', '~> 4.3'
49
- s.add_development_dependency 'simplecov', '~> 0.12'
50
- s.add_development_dependency 'spree_backend', spree_version
51
- s.add_development_dependency 'spree_frontend', spree_version
52
- s.add_development_dependency 'sqlite3'
53
- s.add_development_dependency 'webdrivers', '~> 4.2.0'
31
+ s.add_development_dependency 'spree_dev_tools'
54
32
  end