solidus_auth_devise_devise_token_auth 2.1.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.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +20 -0
- data/CHANGELOG.md +173 -0
- data/Gemfile +36 -0
- data/LICENSE.md +26 -0
- data/README.md +98 -0
- data/Rakefile +21 -0
- data/app/mailers/spree/user_mailer.rb +15 -0
- data/app/models/spree/auth_configuration.rb +9 -0
- data/app/models/spree/user.rb +47 -0
- data/app/overrides/auth_admin_login_navigation_bar.rb +10 -0
- data/app/overrides/auth_shared_login_bar.rb +10 -0
- data/bin/rails +7 -0
- data/circle.yml +6 -0
- data/config/initializers/devise.rb +141 -0
- data/config/initializers/warden.rb +14 -0
- data/config/locales/de.yml +53 -0
- data/config/locales/en.yml +54 -0
- data/config/locales/es.yml +50 -0
- data/config/locales/fr.yml +50 -0
- data/config/locales/it.yml +76 -0
- data/config/locales/nl.yml +50 -0
- data/config/locales/pt-BR.yml +52 -0
- data/config/locales/tr.yml +50 -0
- data/config/locales/zh-CN.yml +54 -0
- data/config/routes.rb +71 -0
- data/db/default/users.rb +75 -0
- data/db/migrate/20101026184949_create_users.rb +29 -0
- data/db/migrate/20101026184950_rename_columns_for_devise.rb +41 -0
- data/db/migrate/20101214150824_convert_user_remember_field.rb +11 -0
- data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +8 -0
- data/db/migrate/20120605211305_make_users_email_index_unique.rb +9 -0
- data/db/migrate/20140904000425_add_deleted_at_to_users.rb +6 -0
- data/db/migrate/20141002154641_add_confirmable_to_users.rb +7 -0
- data/db/seeds.rb +1 -0
- data/lib/assets/javascripts/spree/backend/solidus_auth.js +1 -0
- data/lib/assets/javascripts/spree/frontend/solidus_auth.js +1 -0
- data/lib/assets/stylesheets/spree/backend/solidus_auth.css +3 -0
- data/lib/assets/stylesheets/spree/frontend/solidus_auth.css +3 -0
- data/lib/controllers/backend/spree/admin/admin_controller_decorator.rb +11 -0
- data/lib/controllers/backend/spree/admin/orders/customer_details_controller_decorator.rb +15 -0
- data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +41 -0
- data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +43 -0
- data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +66 -0
- data/lib/controllers/frontend/spree/user_confirmations_controller.rb +14 -0
- data/lib/controllers/frontend/spree/user_passwords_controller.rb +50 -0
- data/lib/controllers/frontend/spree/user_registrations_controller.rb +40 -0
- data/lib/controllers/frontend/spree/user_sessions_controller.rb +64 -0
- data/lib/controllers/frontend/spree/users_controller.rb +57 -0
- data/lib/generators/solidus/auth/install/install_generator.rb +25 -0
- data/lib/generators/solidus/auth/install/templates/config/initializers/devise.rb +1 -0
- data/lib/solidus/auth.rb +2 -0
- data/lib/solidus_auth_devise.rb +13 -0
- data/lib/spree/auth/devise.rb +14 -0
- data/lib/spree/auth/engine.rb +80 -0
- data/lib/spree/authentication_helpers.rb +33 -0
- data/lib/tasks/auth.rake +9 -0
- data/lib/views/backend/spree/admin/shared/_navigation_footer.html.erb +25 -0
- data/lib/views/backend/spree/admin/user_passwords/edit.html.erb +15 -0
- data/lib/views/backend/spree/admin/user_passwords/new.html.erb +17 -0
- data/lib/views/backend/spree/admin/user_sessions/authorization_failure.html.erb +4 -0
- data/lib/views/backend/spree/admin/user_sessions/new.html.erb +31 -0
- data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +13 -0
- data/lib/views/frontend/spree/checkout/registration.html.erb +22 -0
- data/lib/views/frontend/spree/shared/_flashes.html.erb +9 -0
- data/lib/views/frontend/spree/shared/_login.html.erb +18 -0
- data/lib/views/frontend/spree/shared/_login_bar.html.erb +2 -0
- data/lib/views/frontend/spree/shared/_login_bar_items.html.erb +6 -0
- data/lib/views/frontend/spree/shared/_user_form.html.erb +17 -0
- data/lib/views/frontend/spree/user_mailer/confirmation_instructions.text.erb +5 -0
- data/lib/views/frontend/spree/user_mailer/reset_password_instructions.text.erb +10 -0
- data/lib/views/frontend/spree/user_passwords/edit.html.erb +17 -0
- data/lib/views/frontend/spree/user_passwords/new.html.erb +17 -0
- data/lib/views/frontend/spree/user_registrations/new.html.erb +21 -0
- data/lib/views/frontend/spree/user_sessions/authorization_failure.html.erb +4 -0
- data/lib/views/frontend/spree/user_sessions/new.html.erb +13 -0
- data/lib/views/frontend/spree/users/edit.html.erb +14 -0
- data/lib/views/frontend/spree/users/show.html.erb +43 -0
- data/solidus_auth_devise.gemspec +41 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +196 -0
- data/spec/controllers/spree/products_controller_spec.rb +27 -0
- data/spec/controllers/spree/user_passwords_controller_spec.rb +44 -0
- data/spec/controllers/spree/user_registrations_controller_spec.rb +96 -0
- data/spec/controllers/spree/user_sessions_controller_spec.rb +113 -0
- data/spec/controllers/spree/users_controller_spec.rb +38 -0
- data/spec/factories/confirmed_user.rb +7 -0
- data/spec/features/account_spec.rb +58 -0
- data/spec/features/admin/orders_spec.rb +30 -0
- data/spec/features/admin/password_reset_spec.rb +24 -0
- data/spec/features/admin/products_spec.rb +9 -0
- data/spec/features/admin/sign_in_spec.rb +44 -0
- data/spec/features/admin/sign_out_spec.rb +22 -0
- data/spec/features/admin_permissions_spec.rb +46 -0
- data/spec/features/change_email_spec.rb +26 -0
- data/spec/features/checkout_spec.rb +181 -0
- data/spec/features/confirmation_spec.rb +32 -0
- data/spec/features/order_spec.rb +62 -0
- data/spec/features/password_reset_spec.rb +24 -0
- data/spec/features/sign_in_spec.rb +52 -0
- data/spec/features/sign_out_spec.rb +25 -0
- data/spec/features/sign_up_spec.rb +30 -0
- data/spec/mailers/user_mailer_spec.rb +46 -0
- data/spec/models/order_spec.rb +26 -0
- data/spec/models/user_spec.rb +63 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/ability.rb +15 -0
- data/spec/support/authentication_helpers.rb +14 -0
- data/spec/support/confirm_helpers.rb +13 -0
- data/spec/support/email.rb +5 -0
- data/spec/support/preferences.rb +5 -0
- data/spec/support/spree.rb +10 -0
- metadata +446 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
RSpec.describe Spree::UserSessionsController, type: :controller do
|
|
2
|
+
let(:user) { create(:user) }
|
|
3
|
+
|
|
4
|
+
before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
|
|
5
|
+
|
|
6
|
+
context "#create" do
|
|
7
|
+
let(:format) { :html }
|
|
8
|
+
let(:password) { 'secret' }
|
|
9
|
+
|
|
10
|
+
subject do
|
|
11
|
+
post(:create, {
|
|
12
|
+
params: {
|
|
13
|
+
spree_user: {
|
|
14
|
+
email: user.email,
|
|
15
|
+
password: password
|
|
16
|
+
},
|
|
17
|
+
format: format
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context "when using correct login information" do
|
|
23
|
+
context 'with a guest token present' do
|
|
24
|
+
before do
|
|
25
|
+
request.cookie_jar.signed[:guest_token] = 'ABC'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'assigns orders with the correct token and no user present' do
|
|
29
|
+
order = create(:order, email: user.email, guest_token: 'ABC', user_id: nil, created_by_id: nil)
|
|
30
|
+
subject
|
|
31
|
+
|
|
32
|
+
order.reload
|
|
33
|
+
expect(order.user_id).to eq user.id
|
|
34
|
+
expect(order.created_by_id).to eq user.id
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'assigns orders with the correct token and no user or email present' do
|
|
38
|
+
order = create(:order, guest_token: 'ABC', user_id: nil, created_by_id: nil)
|
|
39
|
+
subject
|
|
40
|
+
|
|
41
|
+
order.reload
|
|
42
|
+
expect(order.user_id).to eq user.id
|
|
43
|
+
expect(order.created_by_id).to eq user.id
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'does not assign completed orders' do
|
|
47
|
+
order = create(:order, email: user.email, guest_token: 'ABC',
|
|
48
|
+
user_id: nil, created_by_id: nil,
|
|
49
|
+
completed_at: 1.minute.ago)
|
|
50
|
+
subject
|
|
51
|
+
|
|
52
|
+
order.reload
|
|
53
|
+
expect(order.user_id).to be_nil
|
|
54
|
+
expect(order.created_by_id).to be_nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it 'does not assign orders with an existing user' do
|
|
58
|
+
order = create(:order, guest_token: 'ABC', user_id: 200)
|
|
59
|
+
subject
|
|
60
|
+
|
|
61
|
+
expect(order.reload.user_id).to eq 200
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'does not assign orders with a different token' do
|
|
65
|
+
order = create(:order, guest_token: 'DEF', user_id: nil, created_by_id: nil)
|
|
66
|
+
subject
|
|
67
|
+
|
|
68
|
+
expect(order.reload.user_id).to be_nil
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context "when html format is requested" do
|
|
73
|
+
it "redirects to default after signing in" do
|
|
74
|
+
subject
|
|
75
|
+
expect(response).to redirect_to spree.root_path
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
context "when js format is requested" do
|
|
80
|
+
let(:format) { :js }
|
|
81
|
+
|
|
82
|
+
it "returns a json with ship and bill address" do
|
|
83
|
+
subject
|
|
84
|
+
parsed = ActiveSupport::JSON.decode(response.body)
|
|
85
|
+
expect(parsed).to have_key("user")
|
|
86
|
+
expect(parsed).to have_key("ship_address")
|
|
87
|
+
expect(parsed).to have_key("bill_address")
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "when using incorrect login information" do
|
|
93
|
+
let(:password) { 'wrong' }
|
|
94
|
+
|
|
95
|
+
context "when html format is requested" do
|
|
96
|
+
it "renders new template again with errors" do
|
|
97
|
+
subject
|
|
98
|
+
expect(response).to render_template(:new)
|
|
99
|
+
expect(flash[:error]).to eq I18n.t(:'devise.failure.invalid')
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context "when js format is requested" do
|
|
104
|
+
let(:format) { :js }
|
|
105
|
+
it "returns json with the error" do
|
|
106
|
+
subject
|
|
107
|
+
parsed = ActiveSupport::JSON.decode(response.body)
|
|
108
|
+
expect(parsed).to have_key("error")
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
RSpec.describe Spree::UsersController, type: :controller do
|
|
2
|
+
|
|
3
|
+
let(:admin_user) { create(:user) }
|
|
4
|
+
let(:user) { create(:user) }
|
|
5
|
+
let(:role) { create(:role) }
|
|
6
|
+
|
|
7
|
+
before { allow(controller).to receive(:spree_current_user) { user } }
|
|
8
|
+
|
|
9
|
+
context '#load_object' do
|
|
10
|
+
it 'redirects to signup path if user is not found' do
|
|
11
|
+
allow(controller).to receive(:spree_current_user) { nil }
|
|
12
|
+
put :update, params: { user: { email: 'foobar@example.com' } }
|
|
13
|
+
expect(response).to redirect_to spree.login_path
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context '#create' do
|
|
18
|
+
it 'creates a new user' do
|
|
19
|
+
post :create, params: { user: { email: 'foobar@example.com', password: 'foobar123', password_confirmation: 'foobar123' } }
|
|
20
|
+
expect(assigns[:user].new_record?).to be false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context '#update' do
|
|
25
|
+
context 'when updating own account' do
|
|
26
|
+
it 'performs update' do
|
|
27
|
+
put :update, params: { user: { email: 'mynew@email-address.com' } }
|
|
28
|
+
expect(assigns[:user].email).to eq 'mynew@email-address.com'
|
|
29
|
+
expect(response).to redirect_to spree.account_url(only_path: true)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'does not update roles' do
|
|
34
|
+
put :update, params: { user: { spree_role_ids: [role.id] } }
|
|
35
|
+
expect(assigns[:user].spree_roles).to_not include role
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
RSpec.feature 'Accounts', type: :feature do
|
|
2
|
+
|
|
3
|
+
context 'editing' do
|
|
4
|
+
scenario 'can edit an admin user' do
|
|
5
|
+
user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
|
|
6
|
+
visit spree.login_path
|
|
7
|
+
|
|
8
|
+
fill_in 'Email', with: user.email
|
|
9
|
+
fill_in 'Password', with: user.password
|
|
10
|
+
click_button 'Login'
|
|
11
|
+
|
|
12
|
+
click_link 'My Account'
|
|
13
|
+
expect(page).to have_text 'admin@person.com'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
scenario 'can edit a new user' do
|
|
17
|
+
Spree::Auth::Config.set(signout_after_password_change: false)
|
|
18
|
+
visit spree.signup_path
|
|
19
|
+
|
|
20
|
+
fill_in 'Email', with: 'email@person.com'
|
|
21
|
+
fill_in 'Password', with: 'password'
|
|
22
|
+
fill_in 'Password Confirmation', with: 'password'
|
|
23
|
+
click_button 'Create'
|
|
24
|
+
|
|
25
|
+
click_link 'My Account'
|
|
26
|
+
expect(page).to have_text 'email@person.com'
|
|
27
|
+
click_link 'Edit'
|
|
28
|
+
|
|
29
|
+
fill_in 'Password', with: 'foobar'
|
|
30
|
+
fill_in 'Password Confirmation', with: 'foobar'
|
|
31
|
+
click_button 'Update'
|
|
32
|
+
|
|
33
|
+
expect(page).to have_text 'email@person.com'
|
|
34
|
+
expect(page).to have_text 'Account updated'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
scenario 'can edit an existing user account' do
|
|
38
|
+
Spree::Auth::Config.set(signout_after_password_change: false)
|
|
39
|
+
user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret')
|
|
40
|
+
visit spree.login_path
|
|
41
|
+
|
|
42
|
+
fill_in 'Email', with: user.email
|
|
43
|
+
fill_in 'Password', with: user.password
|
|
44
|
+
click_button 'Login'
|
|
45
|
+
|
|
46
|
+
click_link 'My Account'
|
|
47
|
+
expect(page).to have_text 'email@person.com'
|
|
48
|
+
click_link 'Edit'
|
|
49
|
+
|
|
50
|
+
fill_in 'Password', with: 'foobar'
|
|
51
|
+
fill_in 'Password Confirmation', with: 'foobar'
|
|
52
|
+
click_button 'Update'
|
|
53
|
+
|
|
54
|
+
expect(page).to have_text 'email@person.com'
|
|
55
|
+
expect(page).to have_text 'Account updated'
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
RSpec.feature 'Admin orders', type: :feature do
|
|
2
|
+
|
|
3
|
+
background do
|
|
4
|
+
create(:store)
|
|
5
|
+
sign_in_as! create(:admin_user)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Regression #203
|
|
9
|
+
scenario 'can list orders' do
|
|
10
|
+
expect { visit spree.admin_orders_path }.not_to raise_error
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Regression #203
|
|
14
|
+
scenario 'can new orders' do
|
|
15
|
+
FactoryBot.create(:country)
|
|
16
|
+
expect { visit spree.new_admin_order_path }.not_to raise_error
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Regression #203
|
|
20
|
+
scenario 'can not edit orders' do
|
|
21
|
+
expect { visit spree.edit_admin_order_path('nodata') }.to raise_error(ActiveRecord::RecordNotFound)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Regression #203
|
|
25
|
+
scenario 'can edit orders' do
|
|
26
|
+
create(:order, number: 'R123')
|
|
27
|
+
visit spree.edit_admin_order_path('R123')
|
|
28
|
+
expect(page).not_to have_text 'Authorization Failure'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
RSpec.feature 'Admin - Reset Password', type: :feature do
|
|
2
|
+
|
|
3
|
+
let!(:store) { create(:store) }
|
|
4
|
+
|
|
5
|
+
background do
|
|
6
|
+
ActionMailer::Base.default_url_options[:host] = 'http://example.com'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
scenario 'allows a user to supply an email for the password reset' do
|
|
10
|
+
user = create(:user, email: 'foobar@example.com', password: 'secret', password_confirmation: 'secret')
|
|
11
|
+
visit spree.admin_login_path
|
|
12
|
+
click_link 'Forgot Password?'
|
|
13
|
+
fill_in 'Email', with: 'foobar@example.com'
|
|
14
|
+
click_button 'Reset my password'
|
|
15
|
+
expect(page).to have_text 'You will receive an email with instructions'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
scenario 'shows errors if no email is supplied' do
|
|
19
|
+
visit spree.admin_login_path
|
|
20
|
+
click_link 'Forgot Password?'
|
|
21
|
+
click_button 'Reset my password'
|
|
22
|
+
expect(page).to have_text "Email can't be blank"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
RSpec.feature 'Admin products', type: :feature do
|
|
2
|
+
|
|
3
|
+
context 'as anonymous user' do
|
|
4
|
+
# Regression test for #1250
|
|
5
|
+
scenario 'redirects to login page when attempting to access product listing' do
|
|
6
|
+
expect { visit spree.admin_products_path }.not_to raise_error
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
RSpec.feature 'Admin - Sign In', type: :feature do
|
|
2
|
+
|
|
3
|
+
background do
|
|
4
|
+
@user = create(:user, email: 'email@person.com')
|
|
5
|
+
visit spree.admin_login_path
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
scenario 'asks user to sign in' do
|
|
9
|
+
visit spree.admin_path
|
|
10
|
+
expect(page).not_to have_text 'Authorization Failure'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
scenario 'lets a user sign in successfully' do
|
|
14
|
+
fill_in 'Email', with: @user.email
|
|
15
|
+
fill_in 'Password', with: 'secret'
|
|
16
|
+
click_button 'Login'
|
|
17
|
+
|
|
18
|
+
expect(page).to have_text 'Logged in successfully'
|
|
19
|
+
expect(page).not_to have_text 'Login'
|
|
20
|
+
expect(page).to have_text 'Logout'
|
|
21
|
+
expect(current_path).to eq '/'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
scenario 'shows validation erros' do
|
|
25
|
+
fill_in 'Email', with: @user.email
|
|
26
|
+
fill_in 'Password', with: 'wrong_password'
|
|
27
|
+
click_button 'Login'
|
|
28
|
+
|
|
29
|
+
expect(page).to have_text 'Invalid email or password'
|
|
30
|
+
expect(page).to have_text 'Login'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
scenario 'allows a user to access a restricted page after logging in' do
|
|
34
|
+
user = create(:admin_user, email: 'admin@person.com')
|
|
35
|
+
visit spree.admin_path
|
|
36
|
+
|
|
37
|
+
fill_in 'Email', with: user.email
|
|
38
|
+
fill_in 'Password', with: 'secret'
|
|
39
|
+
click_button 'Login'
|
|
40
|
+
|
|
41
|
+
expect(page).to have_text 'admin@person.com'
|
|
42
|
+
expect(current_path).to eq '/admin/orders'
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
RSpec.feature 'Admin - Sign Out', type: :feature do
|
|
2
|
+
|
|
3
|
+
given!(:user) do
|
|
4
|
+
create :user, email: 'email@person.com'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
background do
|
|
8
|
+
visit spree.admin_login_path
|
|
9
|
+
fill_in 'Email', with: user.email
|
|
10
|
+
fill_in 'Password', with: 'secret'
|
|
11
|
+
# Regression test for #1257
|
|
12
|
+
check 'Remember me'
|
|
13
|
+
click_button 'Login'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
scenario 'allows a signed in user to logout' do
|
|
17
|
+
click_link 'Logout'
|
|
18
|
+
visit spree.admin_login_path
|
|
19
|
+
expect(page).to have_text 'Login'
|
|
20
|
+
expect(page).not_to have_text 'Logout'
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
RSpec.feature 'Admin Permissions', type: :feature do
|
|
2
|
+
|
|
3
|
+
context 'orders' do
|
|
4
|
+
background do
|
|
5
|
+
user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
|
|
6
|
+
Spree::Ability.register_ability(AbilityDecorator)
|
|
7
|
+
visit spree.login_path
|
|
8
|
+
|
|
9
|
+
fill_in 'Email', with: user.email
|
|
10
|
+
fill_in 'Password', with: user.password
|
|
11
|
+
click_button 'Login'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context 'admin is restricted from accessing orders' do
|
|
15
|
+
scenario 'can not list orders' do
|
|
16
|
+
visit spree.admin_orders_path
|
|
17
|
+
expect(page).to have_text 'Authorization Failure'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
scenario 'can not edit orders' do
|
|
21
|
+
create(:order, number: 'R123')
|
|
22
|
+
visit spree.edit_admin_order_path('R123')
|
|
23
|
+
expect(page).to have_text 'Authorization Failure'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
scenario 'can not new orders' do
|
|
27
|
+
visit spree.new_admin_order_path
|
|
28
|
+
expect(page).to have_text 'Authorization Failure'
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "admin is restricted from accessing an order's customer details" do
|
|
33
|
+
given(:order) { create(:order_with_totals) }
|
|
34
|
+
|
|
35
|
+
scenario 'can not list customer details for an order' do
|
|
36
|
+
visit spree.admin_order_customer_path(order)
|
|
37
|
+
expect(page).to have_text 'Authorization Failure'
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
scenario "can not edit an order's customer details" do
|
|
41
|
+
visit spree.edit_admin_order_customer_path(order)
|
|
42
|
+
expect(page).to have_text 'Authorization Failure'
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
RSpec.feature 'Change email', type: :feature do
|
|
2
|
+
|
|
3
|
+
background do
|
|
4
|
+
Spree::Auth::Config.set(signout_after_password_change: false)
|
|
5
|
+
|
|
6
|
+
user = create(:user)
|
|
7
|
+
visit spree.root_path
|
|
8
|
+
click_link 'Login'
|
|
9
|
+
|
|
10
|
+
fill_in 'spree_user[email]', with: user.email
|
|
11
|
+
fill_in 'spree_user[password]', with: 'secret'
|
|
12
|
+
click_button 'Login'
|
|
13
|
+
|
|
14
|
+
visit spree.edit_account_path
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
scenario 'work with correct password' do
|
|
18
|
+
fill_in 'user_email', with: 'tests@example.com'
|
|
19
|
+
fill_in 'user_password', with: 'password'
|
|
20
|
+
fill_in 'user_password_confirmation', with: 'password'
|
|
21
|
+
click_button 'Update'
|
|
22
|
+
|
|
23
|
+
expect(page).to have_text 'Account updated'
|
|
24
|
+
expect(page).to have_text 'tests@example.com'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
RSpec.feature 'Checkout', :js, type: :feature do
|
|
2
|
+
given!(:store) { create(:store) }
|
|
3
|
+
given!(:country) { create(:country, name: 'United States', states_required: true) }
|
|
4
|
+
given!(:state) { create(:state, name: 'Maryland', country: country) }
|
|
5
|
+
given!(:shipping_method) do
|
|
6
|
+
shipping_method = create(:shipping_method)
|
|
7
|
+
calculator = Spree::Calculator::Shipping::PerItem.create!(calculable: shipping_method, preferred_amount: 10)
|
|
8
|
+
shipping_method.calculator = calculator
|
|
9
|
+
shipping_method.tap(&:save)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
given!(:zone) { create(:zone) }
|
|
13
|
+
given!(:address) { create(:address, state: state, country: country) }
|
|
14
|
+
given!(:payment_method){ create :check_payment_method }
|
|
15
|
+
|
|
16
|
+
background do
|
|
17
|
+
@product = create(:product, name: 'RoR Mug')
|
|
18
|
+
@product.master.stock_items.first.update_column(:count_on_hand, 1)
|
|
19
|
+
|
|
20
|
+
# Bypass gateway error on checkout | ..or stub a gateway
|
|
21
|
+
Spree::Config[:allow_checkout_on_gateway_error] = true
|
|
22
|
+
|
|
23
|
+
visit spree.root_path
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Regression test for https://github.com/solidusio/solidus/issues/1588
|
|
27
|
+
scenario 'leaving and returning to address step' do
|
|
28
|
+
Spree::Auth::Config.set(registration_step: true)
|
|
29
|
+
click_link 'RoR Mug'
|
|
30
|
+
click_button 'Add To Cart'
|
|
31
|
+
within('h1') { expect(page).to have_text 'Shopping Cart' }
|
|
32
|
+
click_button 'Checkout'
|
|
33
|
+
|
|
34
|
+
within '#guest_checkout' do
|
|
35
|
+
fill_in 'Email', with: 'test@example.com'
|
|
36
|
+
end
|
|
37
|
+
click_on 'Continue'
|
|
38
|
+
|
|
39
|
+
click_on 'Cart'
|
|
40
|
+
|
|
41
|
+
click_on 'Checkout'
|
|
42
|
+
|
|
43
|
+
expect(page).to have_content "Billing Address"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context 'without payment being required' do
|
|
47
|
+
scenario 'allow a visitor to checkout as guest, without registration' do
|
|
48
|
+
click_link 'RoR Mug'
|
|
49
|
+
click_button 'Add To Cart'
|
|
50
|
+
within('h1') { expect(page).to have_text 'Shopping Cart' }
|
|
51
|
+
click_button 'Checkout'
|
|
52
|
+
|
|
53
|
+
expect(page).to have_content(/Checkout as a Guest/i)
|
|
54
|
+
|
|
55
|
+
within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' }
|
|
56
|
+
click_button 'Continue'
|
|
57
|
+
|
|
58
|
+
expect(page).to have_text(/Billing Address/i)
|
|
59
|
+
expect(page).to have_text(/Shipping Address/i)
|
|
60
|
+
|
|
61
|
+
str_addr = 'bill_address'
|
|
62
|
+
select 'United States', from: "order_#{str_addr}_attributes_country_id"
|
|
63
|
+
%w(firstname lastname address1 city zipcode phone).each do |field|
|
|
64
|
+
fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
|
|
65
|
+
end
|
|
66
|
+
select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
|
|
67
|
+
check 'order_use_billing'
|
|
68
|
+
|
|
69
|
+
click_button 'Save and Continue'
|
|
70
|
+
click_button 'Save and Continue'
|
|
71
|
+
click_button 'Save and Continue'
|
|
72
|
+
click_button 'Place Order'
|
|
73
|
+
|
|
74
|
+
expect(page).to have_text 'Your order has been processed successfully'
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
scenario 'associate an uncompleted guest order with user after logging in' do
|
|
78
|
+
user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
|
|
79
|
+
click_link 'RoR Mug'
|
|
80
|
+
click_button 'Add To Cart'
|
|
81
|
+
|
|
82
|
+
visit spree.login_path
|
|
83
|
+
fill_in 'Email', with: user.email
|
|
84
|
+
fill_in 'Password', with: user.password
|
|
85
|
+
click_button 'Login'
|
|
86
|
+
click_link 'Cart'
|
|
87
|
+
|
|
88
|
+
expect(page).to have_text 'RoR Mug'
|
|
89
|
+
within('h1') { expect(page).to have_text 'Shopping Cart' }
|
|
90
|
+
|
|
91
|
+
click_button 'Checkout'
|
|
92
|
+
|
|
93
|
+
str_addr = 'bill_address'
|
|
94
|
+
select 'United States', from: "order_#{str_addr}_attributes_country_id"
|
|
95
|
+
%w(firstname lastname address1 city zipcode phone).each do |field|
|
|
96
|
+
fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
|
|
97
|
+
end
|
|
98
|
+
select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
|
|
99
|
+
check 'order_use_billing'
|
|
100
|
+
|
|
101
|
+
click_button 'Save and Continue'
|
|
102
|
+
click_button 'Save and Continue'
|
|
103
|
+
click_button 'Save and Continue'
|
|
104
|
+
click_button 'Place Order'
|
|
105
|
+
|
|
106
|
+
expect(page).to have_text 'Your order has been processed successfully'
|
|
107
|
+
expect(Spree::Order.first.user).to eq user
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Regression test for #890
|
|
111
|
+
scenario 'associate an incomplete guest order with user after successful password reset' do
|
|
112
|
+
user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
|
|
113
|
+
click_link 'RoR Mug'
|
|
114
|
+
click_button 'Add To Cart'
|
|
115
|
+
|
|
116
|
+
visit spree.login_path
|
|
117
|
+
click_link 'Forgot Password?'
|
|
118
|
+
fill_in 'spree_user_email', with: 'email@person.com'
|
|
119
|
+
click_button 'Reset my password'
|
|
120
|
+
|
|
121
|
+
# Need to do this now because the token stored in the DB is the encrypted version
|
|
122
|
+
# The 'plain-text' version is sent in the email and there's one way to get that!
|
|
123
|
+
reset_password_email = ActionMailer::Base.deliveries.first
|
|
124
|
+
token_url_regex = /\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
|
|
125
|
+
token = token_url_regex.match(reset_password_email.body.to_s)[1]
|
|
126
|
+
|
|
127
|
+
visit spree.edit_spree_user_password_path(reset_password_token: token)
|
|
128
|
+
fill_in 'Password', with: 'password'
|
|
129
|
+
fill_in 'Password Confirmation', with: 'password'
|
|
130
|
+
click_button 'Update'
|
|
131
|
+
|
|
132
|
+
click_link 'Cart'
|
|
133
|
+
click_button 'Checkout'
|
|
134
|
+
|
|
135
|
+
str_addr = 'bill_address'
|
|
136
|
+
select 'United States', from: "order_#{str_addr}_attributes_country_id"
|
|
137
|
+
%w(firstname lastname address1 city zipcode phone).each do |field|
|
|
138
|
+
fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
|
|
139
|
+
end
|
|
140
|
+
select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
|
|
141
|
+
check 'order_use_billing'
|
|
142
|
+
|
|
143
|
+
click_button 'Save and Continue'
|
|
144
|
+
|
|
145
|
+
expect(page).not_to have_text 'Email is invalid'
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
scenario 'allow a user to register during checkout' do
|
|
149
|
+
click_link 'RoR Mug'
|
|
150
|
+
click_button 'Add To Cart'
|
|
151
|
+
click_button 'Checkout'
|
|
152
|
+
|
|
153
|
+
expect(page).to have_text 'Registration'
|
|
154
|
+
|
|
155
|
+
click_link 'Create a new account'
|
|
156
|
+
|
|
157
|
+
fill_in 'Email', with: 'email@person.com'
|
|
158
|
+
fill_in 'Password', with: 'spree123'
|
|
159
|
+
fill_in 'Password Confirmation', with: 'spree123'
|
|
160
|
+
click_button 'Create'
|
|
161
|
+
|
|
162
|
+
expect(page).to have_text 'You have signed up successfully.'
|
|
163
|
+
|
|
164
|
+
str_addr = 'bill_address'
|
|
165
|
+
select 'United States', from: "order_#{str_addr}_attributes_country_id"
|
|
166
|
+
%w(firstname lastname address1 city zipcode phone).each do |field|
|
|
167
|
+
fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
|
|
168
|
+
end
|
|
169
|
+
select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
|
|
170
|
+
check 'order_use_billing'
|
|
171
|
+
|
|
172
|
+
click_button 'Save and Continue'
|
|
173
|
+
click_button 'Save and Continue'
|
|
174
|
+
click_button 'Save and Continue'
|
|
175
|
+
click_button 'Place Order'
|
|
176
|
+
|
|
177
|
+
expect(page).to have_text 'Your order has been processed successfully'
|
|
178
|
+
expect(Spree::Order.first.user).to eq Spree::User.find_by_email('email@person.com')
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|