spree_auth_devise 4.0.0 → 4.3.1

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.

Potentially problematic release.


This version of spree_auth_devise might be problematic. Click here for more details.

Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +41 -0
  3. data/.gitignore +1 -0
  4. data/.travis.yml +33 -37
  5. data/Appraisals +3 -14
  6. data/Gemfile +1 -1
  7. data/README.md +3 -12
  8. data/Rakefile +9 -3
  9. data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
  10. data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
  11. data/app/controllers/spree/user_confirmations_controller.rb +38 -0
  12. data/app/controllers/spree/user_passwords_controller.rb +9 -1
  13. data/app/controllers/spree/user_registrations_controller.rb +34 -1
  14. data/app/controllers/spree/user_sessions_controller.rb +23 -1
  15. data/app/mailers/spree/user_mailer.rb +11 -4
  16. data/app/models/spree/user.rb +42 -0
  17. data/app/services/spree/account/create.rb +19 -0
  18. data/app/services/spree/account/update.rb +17 -0
  19. data/app/views/spree/user_mailer/confirmation_instructions.html.erb +20 -0
  20. data/app/views/spree/user_mailer/confirmation_instructions.text.erb +8 -5
  21. data/app/views/spree/user_mailer/reset_password_instructions.html.erb +20 -0
  22. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +7 -5
  23. data/app/views/spree/user_passwords/edit.html.erb +20 -17
  24. data/app/views/spree/user_passwords/new.html.erb +17 -15
  25. data/app/views/spree/user_registrations/new.html.erb +12 -17
  26. data/app/views/spree/user_sessions/new.html.erb +11 -12
  27. data/config/locales/de.yml +16 -0
  28. data/config/locales/en.yml +21 -6
  29. data/config/locales/zh-TW.yml +58 -0
  30. data/config/routes.rb +12 -3
  31. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +2 -2
  32. data/gemfiles/{spree_3_2.gemfile → spree_4_1.gemfile} +1 -1
  33. data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
  34. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +3 -2
  35. data/lib/controllers/frontend/spree/users_controller.rb +4 -4
  36. data/lib/generators/spree/auth/install/install_generator.rb +0 -4
  37. data/lib/spree/auth/engine.rb +14 -1
  38. data/lib/spree/testing_support/auth_helpers.rb +36 -0
  39. data/lib/spree/testing_support/checkout_helpers.rb +24 -0
  40. data/lib/spree_auth_devise.rb +0 -1
  41. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +1 -1
  42. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +1 -1
  43. data/spec/controllers/spree/admin/orders_controller_spec.rb +1 -1
  44. data/spec/controllers/spree/admin/user_sessions_controller_spec.rb +1 -1
  45. data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
  46. data/spec/controllers/spree/checkout_controller_spec.rb +12 -13
  47. data/spec/controllers/spree/products_controller_spec.rb +1 -1
  48. data/spec/controllers/spree/user_passwords_controller_spec.rb +4 -4
  49. data/spec/controllers/spree/user_registrations_controller_spec.rb +8 -8
  50. data/spec/controllers/spree/user_sessions_controller_spec.rb +17 -17
  51. data/spec/controllers/spree/users_controller_spec.rb +4 -4
  52. data/spec/features/account_spec.rb +10 -8
  53. data/spec/features/admin/password_reset_spec.rb +2 -4
  54. data/spec/features/admin/sign_in_spec.rb +13 -9
  55. data/spec/features/admin/sign_out_spec.rb +1 -1
  56. data/spec/features/admin_permissions_spec.rb +1 -1
  57. data/spec/features/change_email_spec.rb +1 -7
  58. data/spec/features/checkout_spec.rb +40 -65
  59. data/spec/features/confirmation_spec.rb +4 -6
  60. data/spec/features/order_spec.rb +9 -15
  61. data/spec/features/password_reset_spec.rb +2 -4
  62. data/spec/features/sign_in_spec.rb +21 -17
  63. data/spec/features/sign_out_spec.rb +14 -23
  64. data/spec/features/sign_up_spec.rb +6 -4
  65. data/spec/mailers/user_mailer_spec.rb +4 -4
  66. data/spec/models/user_spec.rb +10 -8
  67. data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
  68. data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
  69. data/spec/spec_helper.rb +7 -22
  70. data/spree_auth_devise.gemspec +14 -27
  71. metadata +35 -337
  72. data/app/overrides/auth_shared_login_bar.rb +0 -6
  73. data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +0 -4
  74. data/app/views/spree/shared/_login.html.erb +0 -18
  75. data/app/views/spree/shared/_user_form.html.erb +0 -17
  76. data/gemfiles/spree_3_5.gemfile +0 -8
  77. data/gemfiles/spree_3_7.gemfile +0 -9
  78. data/gemfiles/spree_4_0.gemfile +0 -8
  79. data/lib/assets/javascripts/spree/backend/spree_auth.js.erb +0 -1
  80. data/lib/assets/javascripts/spree/frontend/account.js +0 -8
  81. data/lib/assets/javascripts/spree/frontend/spree_auth.js.erb +0 -2
  82. data/lib/assets/stylesheets/spree/backend/spree_auth.css.erb +0 -3
  83. data/lib/assets/stylesheets/spree/frontend/spree_auth.css.erb +0 -3
  84. data/lib/controllers/frontend/spree/store_controller_decorator.rb +0 -7
  85. data/lib/views/frontend/spree/checkout/_new_user.html.erb +0 -20
  86. data/lib/views/frontend/spree/checkout/registration.html.erb +0 -25
  87. data/lib/views/frontend/spree/shared/_link_to_account.html.erb +0 -6
  88. data/lib/views/frontend/spree/users/edit.html.erb +0 -17
  89. data/lib/views/frontend/spree/users/show.html.erb +0 -48
  90. data/spec/support/add_to_cart.rb +0 -15
  91. data/spec/support/authentication_helpers.rb +0 -14
  92. data/spec/support/cache_helpers.rb +0 -5
  93. data/spec/support/capybara.rb +0 -16
  94. data/spec/support/database_cleaner.rb +0 -17
  95. data/spec/support/factory_girl.rb +0 -5
  96. data/spec/support/spree.rb +0 -10
@@ -2,7 +2,7 @@ RSpec.describe Spree::ProductsController, type: :controller do
2
2
  let!(:product) { create(:product, available_on: 1.year.from_now) }
3
3
  let!(:user) { build_stubbed(:user, spree_api_key: 'fake') }
4
4
 
5
- subject(:request) { spree_get :show, id: product.to_param }
5
+ subject(:request) { get :show, params: { id: product.to_param }}
6
6
 
7
7
  before do
8
8
  allow(controller).to receive(:before_save_new_order)
@@ -6,14 +6,14 @@ RSpec.describe Spree::UserPasswordsController, type: :controller do
6
6
  describe 'GET edit' do
7
7
  context 'when the user token has not been specified' do
8
8
  it 'redirects to the new session path' do
9
- spree_get :edit
9
+ get :edit
10
10
  expect(response).to redirect_to(
11
11
  'http://test.host/user/spree_user/sign_in'
12
12
  )
13
13
  end
14
14
 
15
15
  it 'flashes an error' do
16
- spree_get :edit
16
+ get :edit
17
17
  expect(flash[:alert]).to include(
18
18
  "You can't access this page without coming from a password reset " \
19
19
  'email'
@@ -23,7 +23,7 @@ RSpec.describe Spree::UserPasswordsController, type: :controller do
23
23
 
24
24
  context 'when the user token has been specified' do
25
25
  it 'does something' do
26
- spree_get :edit, reset_password_token: token
26
+ get :edit, params: { reset_password_token: token }
27
27
  expect(response.code).to eq('200')
28
28
  end
29
29
  end
@@ -32,7 +32,7 @@ RSpec.describe Spree::UserPasswordsController, type: :controller do
32
32
  context '#update' do
33
33
  context 'when updating password with blank password' do
34
34
  it 'shows error flash message, sets spree_user with token and re-displays password edit form' do
35
- spree_put :update, { spree_user: { password: '', password_confirmation: '', reset_password_token: token } }
35
+ put :update, params: { spree_user: { password: '', password_confirmation: '', reset_password_token: token } }
36
36
  expect(assigns(:spree_user).is_a?(Spree::User)).to eq true
37
37
  expect(assigns(:spree_user).reset_password_token).to eq token
38
38
  expect(flash[:error]).to eq I18n.t(:cannot_be_blank, scope: [:devise, :user_passwords, :spree_user])
@@ -2,11 +2,11 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do
2
2
  before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
3
3
 
4
4
  context '#create' do
5
- before { allow(controller).to receive(:after_sign_up_path_for).and_return(spree.root_path(thing: 7)) }
5
+ before { allow(controller).to receive(:after_sign_up_path_for).and_return(spree.account_path) }
6
6
 
7
- it 'redirects to after_sign_up_path_for' do
8
- spree_post :create, { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
9
- expect(response).to redirect_to spree.root_path(thing: 7)
7
+ it 'redirects to account_path' do
8
+ post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
9
+ expect(response).to redirect_to spree.account_path
10
10
  end
11
11
 
12
12
  context 'with a guest token present' do
@@ -24,8 +24,8 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do
24
24
  else
25
25
  order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
26
26
  end
27
- spree_post :create, spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }
28
- user = Spree::User.find_by_email('foobar@example.com')
27
+ post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }}
28
+ user = Spree.user_class.find_by_email('foobar@example.com')
29
29
 
30
30
  order.reload
31
31
  expect(order.user_id).to eq user.id
@@ -38,7 +38,7 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do
38
38
  else
39
39
  order = create(:order, guest_token: 'ABC', user_id: 200)
40
40
  end
41
- spree_post :create, spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }
41
+ post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }}
42
42
 
43
43
  expect(order.reload.user_id).to eq 200
44
44
  end
@@ -49,7 +49,7 @@ RSpec.describe Spree::UserRegistrationsController, type: :controller do
49
49
  else
50
50
  order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
51
51
  end
52
- spree_post :create, spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }
52
+ post :create, params: { spree_user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' }}
53
53
 
54
54
  expect(order.reload.user_id).to be_nil
55
55
  end
@@ -14,7 +14,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
14
14
 
15
15
  it 'assigns orders with the correct token and no user present' do
16
16
  order = create(:order, email: user.email, token: 'ABC', user_id: nil, created_by_id: nil)
17
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
17
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
18
18
 
19
19
  order.reload
20
20
  expect(order.user_id).to eq user.id
@@ -23,7 +23,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
23
23
 
24
24
  it 'assigns orders with the correct token and no user or email present' do
25
25
  order = create(:order, token: 'ABC', user_id: nil, created_by_id: nil)
26
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
26
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
27
27
 
28
28
  order.reload
29
29
  expect(order.user_id).to eq user.id
@@ -34,7 +34,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
34
34
  order = create(:order, email: user.email, token: 'ABC',
35
35
  user_id: nil, created_by_id: nil,
36
36
  completed_at: 1.minute.ago)
37
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
37
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
38
38
 
39
39
  order.reload
40
40
  expect(order.user_id).to be_nil
@@ -43,14 +43,14 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
43
43
 
44
44
  it 'does not assign orders with an existing user' do
45
45
  order = create(:order, token: 'ABC', user_id: 200)
46
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
46
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
47
47
 
48
48
  expect(order.reload.user_id).to eq 200
49
49
  end
50
50
 
51
51
  it 'does not assign orders with a different token' do
52
52
  order = create(:order, token: 'DEF', user_id: nil, created_by_id: nil)
53
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
53
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
54
54
 
55
55
  expect(order.reload.user_id).to be_nil
56
56
  end
@@ -72,7 +72,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
72
72
  else
73
73
  order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil)
74
74
  end
75
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
75
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
76
76
 
77
77
  order.reload
78
78
  expect(order.user_id).to eq user.id
@@ -85,7 +85,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
85
85
  else
86
86
  order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
87
87
  end
88
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
88
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
89
89
 
90
90
  order.reload
91
91
  expect(order.user_id).to eq user.id
@@ -102,7 +102,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
102
102
  user_id: nil, created_by_id: nil,
103
103
  completed_at: 1.minute.ago)
104
104
  end
105
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
105
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
106
106
 
107
107
  order.reload
108
108
  expect(order.user_id).to be_nil
@@ -115,7 +115,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
115
115
  else
116
116
  order = create(:order, guest_token: 'ABC', user_id: 200)
117
117
  end
118
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
118
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
119
119
 
120
120
  expect(order.reload.user_id).to eq 200
121
121
  end
@@ -126,7 +126,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
126
126
  else
127
127
  order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
128
128
  end
129
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
129
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
130
130
 
131
131
  expect(order.reload.user_id).to be_nil
132
132
  end
@@ -144,7 +144,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
144
144
  else
145
145
  order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil)
146
146
  end
147
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
147
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
148
148
 
149
149
  order.reload
150
150
  expect(order.user_id).to eq user.id
@@ -153,15 +153,15 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
153
153
  end
154
154
 
155
155
  context "and html format is used" do
156
- it "redirects to default after signing in" do
157
- spree_post :create, spree_user: { email: user.email, password: 'secret' }
158
- expect(response).to redirect_to spree.root_path
156
+ it "redirects to account path after signing in" do
157
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }}
158
+ expect(response).to redirect_to spree.account_path
159
159
  end
160
160
  end
161
161
 
162
162
  context "and js format is used" do
163
163
  it "returns a json with ship and bill address" do
164
- spree_post :create, spree_user: { email: user.email, password: 'secret' }, format: 'js'
164
+ post :create, params: { spree_user: { email: user.email, password: 'secret' }, format: 'js' }
165
165
  parsed = ActiveSupport::JSON.decode(response.body)
166
166
  expect(parsed).to have_key("user")
167
167
  expect(parsed).to have_key("ship_address")
@@ -173,7 +173,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
173
173
  context "using incorrect login information" do
174
174
  context "and html format is used" do
175
175
  it "renders new template again with errors" do
176
- spree_post :create, spree_user: { email: user.email, password: 'wrong' }
176
+ post :create, params: { spree_user: { email: user.email, password: 'wrong' }}
177
177
  expect(response).to render_template('new')
178
178
  expect(flash[:error]).to eq I18n.t(:'devise.failure.invalid')
179
179
  end
@@ -181,7 +181,7 @@ RSpec.describe Spree::UserSessionsController, type: :controller do
181
181
 
182
182
  context "and js format is used" do
183
183
  it "returns a json with the error" do
184
- spree_post :create, spree_user: { email: user.email, password: 'wrong' }, format: 'js'
184
+ post :create, params: { spree_user: { email: user.email, password: 'wrong' }, format: 'js' }
185
185
  parsed = ActiveSupport::JSON.decode(response.body)
186
186
  expect(parsed).to have_key("error")
187
187
  end
@@ -8,14 +8,14 @@ RSpec.describe Spree::UsersController, type: :controller do
8
8
  context '#load_object' do
9
9
  it 'redirects to signup path if user is not found' do
10
10
  allow(controller).to receive(:spree_current_user) { nil }
11
- spree_put :update, { user: { email: 'foobar@example.com' } }
11
+ put :update, params: { user: { email: 'foobar@example.com' } }
12
12
  expect(response).to redirect_to spree.login_path
13
13
  end
14
14
  end
15
15
 
16
16
  context '#create' do
17
17
  it 'creates a new user' do
18
- spree_post :create, { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
18
+ post :create, params: { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
19
19
  expect(assigns[:user].new_record?).to be false
20
20
  end
21
21
  end
@@ -23,14 +23,14 @@ RSpec.describe Spree::UsersController, type: :controller do
23
23
  context '#update' do
24
24
  context 'when updating own account' do
25
25
  it 'performs update' do
26
- spree_put :update, { user: { email: 'mynew@email-address.com' } }
26
+ put :update, params: { user: { email: 'mynew@email-address.com' } }
27
27
  expect(assigns[:user].email).to eq 'mynew@email-address.com'
28
28
  expect(response).to redirect_to spree.account_url(only_path: true)
29
29
  end
30
30
  end
31
31
 
32
32
  it 'does not update roles' do
33
- spree_put :update, user: { spree_role_ids: [role.id] }
33
+ put :update, params: { user: { spree_role_ids: [role.id] }}
34
34
  expect(assigns[:user].spree_roles).to_not include role
35
35
  end
36
36
  end
@@ -10,9 +10,9 @@ RSpec.feature 'Accounts', type: :feature do
10
10
 
11
11
  fill_in 'Email', with: user.email
12
12
  fill_in 'Password', with: user.password
13
- click_button 'Login'
13
+ click_button 'Log in'
14
14
 
15
- click_link 'My Account'
15
+ show_user_account
16
16
  expect(page).to have_text 'admin@person.com'
17
17
  end
18
18
 
@@ -22,11 +22,12 @@ RSpec.feature 'Accounts', type: :feature do
22
22
  fill_in 'Email', with: 'email@person.com'
23
23
  fill_in 'Password', with: 'password'
24
24
  fill_in 'Password Confirmation', with: 'password'
25
- click_button 'Create'
25
+ click_button 'Sign Up'
26
26
 
27
- click_link 'My Account'
27
+ show_user_account
28
28
  expect(page).to have_text 'email@person.com'
29
- click_link 'Edit'
29
+
30
+ find('a.account-page-user-info-item-title-edit').click
30
31
 
31
32
  fill_in 'Password', with: 'foobar'
32
33
  fill_in 'Password Confirmation', with: 'foobar'
@@ -42,11 +43,12 @@ RSpec.feature 'Accounts', type: :feature do
42
43
 
43
44
  fill_in 'Email', with: user.email
44
45
  fill_in 'Password', with: user.password
45
- click_button 'Login'
46
+ click_button 'Log in'
46
47
 
47
- click_link 'My Account'
48
+ show_user_account
48
49
  expect(page).to have_text 'email@person.com'
49
- click_link 'Edit'
50
+
51
+ find('a.account-page-user-info-item-title-edit').click
50
52
 
51
53
  fill_in 'Password', with: 'foobar'
52
54
  fill_in 'Password Confirmation', with: 'foobar'
@@ -1,6 +1,4 @@
1
1
  RSpec.feature 'Admin - Reset Password', type: :feature do
2
- let!(:store) { create(:store) }
3
-
4
2
  background do
5
3
  ActionMailer::Base.default_url_options[:host] = 'http://example.com'
6
4
  end
@@ -8,7 +6,7 @@ RSpec.feature 'Admin - Reset Password', type: :feature do
8
6
  scenario 'allows a user to supply an email for the password reset' do
9
7
  user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret')
10
8
  visit spree.admin_login_path
11
- click_link 'Forgot Password?'
9
+ click_link 'Forgot password?'
12
10
  fill_in 'Email', with: 'foobar@example.com'
13
11
  click_button 'Reset my password'
14
12
  expect(page).to have_text 'You will receive an email with instructions'
@@ -16,7 +14,7 @@ RSpec.feature 'Admin - Reset Password', type: :feature do
16
14
 
17
15
  scenario 'shows errors if no email is supplied' do
18
16
  visit spree.admin_login_path
19
- click_link 'Forgot Password?'
17
+ click_link 'Forgot password?'
20
18
  click_button 'Reset my password'
21
19
  expect(page).to have_text "Email can't be blank"
22
20
  end
@@ -10,14 +10,12 @@ RSpec.feature 'Admin - Sign In', type: :feature do
10
10
  end
11
11
 
12
12
  scenario 'lets a user sign in successfully', js: true do
13
- fill_in 'Email', with: @user.email
14
- fill_in 'Password', with: 'secret'
15
- click_button 'Login'
13
+ log_in(email: @user.email, password: 'secret')
14
+ show_user_menu
16
15
 
17
- expect(page).to have_text 'Logged in successfully'
18
16
  expect(page).not_to have_text 'Login'
19
- expect(page).to have_text 'Logout'
20
- expect(current_path).to eq '/'
17
+ expect(page).to have_text 'LOG OUT'
18
+ expect(current_path).to eq '/account'
21
19
  end
22
20
 
23
21
  scenario 'shows validation errors' do
@@ -35,9 +33,15 @@ RSpec.feature 'Admin - Sign In', type: :feature do
35
33
 
36
34
  fill_in 'Email', with: user.email
37
35
  fill_in 'Password', with: 'secret'
38
- click_button 'Login'
39
- within '.user-menu' do
40
- expect(page).to have_text 'admin@person.com'
36
+ click_button 'Log in'
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
41
45
  end
42
46
  expect(current_path).to eq '/admin/orders'
43
47
  end
@@ -13,7 +13,7 @@ RSpec.feature 'Admin - Sign Out', type: :feature do
13
13
  end
14
14
 
15
15
  scenario 'allows a signed in user to logout', js: true do
16
- click_link 'Logout'
16
+ log_out
17
17
  visit spree.admin_login_path
18
18
  expect(page).to have_button 'Login'
19
19
  expect(page).not_to have_text 'Logout'
@@ -7,7 +7,7 @@ RSpec.feature 'Admin Permissions', type: :feature do
7
7
 
8
8
  fill_in 'Email', with: user.email
9
9
  fill_in 'Password', with: user.password
10
- click_button 'Login'
10
+ click_button 'Log in'
11
11
  end
12
12
 
13
13
  context 'admin is restricted from accessing orders' do
@@ -3,13 +3,7 @@ RSpec.feature 'Change email', type: :feature do
3
3
  allow_bypass_sign_in
4
4
 
5
5
  user = create(:user, email: 'old@spree.com', password: 'secret')
6
- visit spree.root_path
7
- click_link 'Login'
8
-
9
- fill_in 'spree_user[email]', with: user.email
10
- fill_in 'spree_user[password]', with: 'secret'
11
- click_button 'Login'
12
-
6
+ log_in(email: user.email, password: 'secret')
13
7
  visit spree.edit_account_path
14
8
  end
15
9
 
@@ -1,5 +1,4 @@
1
1
  RSpec.feature 'Checkout', :js, type: :feature do
2
- given!(:store) { create(:store) }
3
2
  given!(:country) { create(:country, name: 'United States', states_required: true) }
4
3
  given!(:state) { create(:state, name: 'Maryland', country: country) }
5
4
  given!(:shipping_method) do
@@ -9,12 +8,13 @@ RSpec.feature 'Checkout', :js, type: :feature do
9
8
  shipping_method.tap(&:save)
10
9
  end
11
10
 
11
+ given!(:user) { create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password') }
12
12
  given!(:zone) { create(:zone) }
13
13
  given!(:address) { create(:address, state: state, country: country) }
14
+ given!(:mug) { create(:product, name: 'RoR Mug') }
14
15
 
15
16
  background do
16
- @product = create(:product, name: 'RoR Mug')
17
- @product.master.stock_items.first.update_column(:count_on_hand, 1)
17
+ mug.master.stock_items.first.update_column(:count_on_hand, 1)
18
18
 
19
19
  # Bypass gateway error on checkout | ..or stub a gateway
20
20
  Spree::Config[:allow_checkout_on_gateway_error] = true
@@ -31,127 +31,102 @@ RSpec.feature 'Checkout', :js, type: :feature do
31
31
 
32
32
  scenario 'allow a visitor to checkout as guest, without registration' do
33
33
  Spree::Auth::Config.set(registration_step: true)
34
- add_to_cart 'RoR Mug'
35
- click_button 'Checkout'
34
+ add_to_cart(mug)
35
+ click_link 'checkout'
36
36
 
37
- expect(page).to have_content(/Checkout as a Guest/i)
37
+ expect(page).to have_selector(:button, 'Continue as a guest')
38
38
 
39
- within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' }
39
+ within('#checkout_form_registration') { fill_in 'Email', with: 'spree@test.com' }
40
40
  click_button 'Continue'
41
41
 
42
42
  expect(page).to have_text(/Billing Address/i)
43
43
  expect(page).to have_text(/Shipping Address/i)
44
44
 
45
- str_addr = 'bill_address'
46
- select 'United States', from: "order_#{str_addr}_attributes_country_id"
47
- %w(firstname lastname address1 city zipcode phone).each do |field|
48
- fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
49
- end
50
- select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
51
- check 'order_use_billing'
52
-
45
+ fill_in_address
53
46
  click_button 'Save and Continue'
54
47
  click_button 'Save and Continue'
55
48
 
56
- expect(page).to have_text 'Your order has been processed successfully'
49
+ expect(page).to have_text 'Order placed successfully'
57
50
  end
58
51
 
59
52
  scenario 'associate an uncompleted guest order with user after logging in' do
60
- user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
61
- add_to_cart 'RoR Mug'
53
+ add_to_cart(mug)
62
54
 
63
55
  visit spree.login_path
64
56
  fill_in 'Email', with: user.email
65
57
  fill_in 'Password', with: user.password
66
- click_button 'Login'
67
- expect(page).to have_text('Cart')
68
- click_link 'Cart'
58
+ click_button 'Log in'
59
+ expect(page).to have_text('Logged in successfully')
60
+ find('a.cart-icon').click
69
61
 
70
62
  expect(page).to have_text 'RoR Mug'
71
- within('h1') { expect(page).to have_text 'Shopping Cart' }
72
-
73
- click_button 'Checkout'
63
+ within('h1') { expect(page).to have_text 'YOUR SHOPPING CART' }
74
64
 
75
- str_addr = 'bill_address'
76
- select 'United States', from: "order_#{str_addr}_attributes_country_id"
77
- %w(firstname lastname address1 city zipcode phone).each do |field|
78
- fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
79
- end
80
- select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
81
- check 'order_use_billing'
65
+ click_link 'checkout'
82
66
 
67
+ fill_in_address
83
68
  click_button 'Save and Continue'
84
69
  click_button 'Save and Continue'
85
70
 
86
- expect(page).to have_text 'Your order has been processed successfully'
71
+ expect(page).to have_text 'Order placed successfully'
87
72
  expect(Spree::Order.first.user).to eq user
88
73
  end
89
74
 
90
75
  # Regression test for #890
91
76
  scenario 'associate an incomplete guest order with user after successful password reset' do
92
- create(:store)
93
- user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
94
- add_to_cart 'RoR Mug'
77
+ add_to_cart(mug)
95
78
 
96
79
  visit spree.login_path
97
- click_link 'Forgot Password?'
98
- fill_in 'spree_user_email', with: 'email@person.com'
80
+ click_link 'Forgot password?'
81
+ fill_in('Email', with: 'email@person.com')
82
+ find('#spree_user_email').set('email@person.com')
83
+
99
84
  click_button 'Reset my password'
100
85
 
101
86
  # Need to do this now because the token stored in the DB is the encrypted version
102
87
  # The 'plain-text' version is sent in the email and there's one way to get that!
103
88
  reset_password_email = ActionMailer::Base.deliveries.first
104
89
  token_url_regex = /^http:\/\/www.example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
105
- token = token_url_regex.match(reset_password_email.body.to_s)[1]
90
+ token = token_url_regex.match(reset_password_email.body.encoded)[1]
106
91
 
107
- visit spree.edit_spree_user_password_path(reset_password_token: token)
92
+ visit spree.edit_spree_user_password_path(reset_password_token: token).tr("%0D","")
108
93
  fill_in 'Password', with: 'password'
109
94
  fill_in 'Password Confirmation', with: 'password'
110
95
  click_button 'Update'
111
96
 
112
- expect(page).to have_text('Cart')
113
- click_link 'Cart'
97
+ expect(page).to have_text('Your password was changed successfully')
98
+ find('a.cart-icon').click
114
99
  expect(page).to have_text('RoR Mug')
115
- click_button 'Checkout'
116
-
117
- str_addr = 'bill_address'
118
- select 'United States', from: "order_#{str_addr}_attributes_country_id"
119
- %w(firstname lastname address1 city zipcode phone).each do |field|
120
- fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
121
- end
122
- select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
123
- check 'order_use_billing'
100
+ click_link 'checkout'
124
101
 
102
+ fill_in_address
125
103
  click_button 'Save and Continue'
126
104
 
127
105
  expect(page).not_to have_text 'Email is invalid'
128
106
  end
129
107
 
130
108
  scenario 'allow a user to register during checkout' do
131
- add_to_cart 'RoR Mug'
132
- click_button 'Checkout'
109
+ add_to_cart(mug)
110
+ click_link 'checkout'
133
111
 
134
- expect(page).to have_text 'Registration'
112
+ expect(page).to have_selector(:link, 'Sign Up')
135
113
 
136
- fill_in 'Email', with: 'email@person.com', match: :first
114
+ click_link 'Sign Up'
115
+
116
+ fill_in 'Email', with: 'test@person.com'
137
117
  fill_in 'Password', with: 'spree123'
138
118
  fill_in 'Password Confirmation', with: 'spree123'
139
- click_button 'Create'
140
- expect(page).to have_text 'You have signed up successfully.'
141
119
 
142
- str_addr = 'bill_address'
143
- select 'United States', from: "order_#{str_addr}_attributes_country_id"
144
- %w(firstname lastname address1 city zipcode phone).each do |field|
145
- fill_in "order_#{str_addr}_attributes_#{field}", with: address.send(field).to_s
146
- end
147
- select address.state.name.to_s, from: "order_#{str_addr}_attributes_state_id"
148
- check 'order_use_billing'
120
+ click_button 'Sign Up'
121
+
122
+ expect(page).to have_text 'You have signed up successfully.'
149
123
 
124
+ fill_in_address
150
125
  click_button 'Save and Continue'
151
126
  click_button 'Save and Continue'
152
127
 
153
- expect(page).to have_text 'Your order has been processed successfully'
154
- expect(Spree::Order.first.user).to eq Spree::User.find_by_email('email@person.com')
128
+ expect(page).to have_text 'Order placed successfully'
129
+ expect(Spree::Order.first.user).to eq Spree.user_class.find_by_email('test@person.com')
155
130
  end
156
131
  end
157
132
  end