spree_auth_devise 1.3.1 → 3.0.5
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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +11 -0
- data/Gemfile +5 -0
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +86 -10
- data/Rakefile +15 -0
- data/Versionfile +5 -0
- data/app/controllers/metal_decorator.rb +6 -0
- data/app/mailers/spree/user_mailer.rb +12 -5
- data/app/models/spree/auth_configuration.rb +1 -0
- data/app/models/spree/user.rb +17 -50
- data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +4 -0
- data/bin/rails +7 -0
- data/circle.yml +11 -0
- data/config.ru +4 -0
- data/config/initializers/devise.rb +3 -8
- data/config/initializers/warden.rb +14 -0
- data/config/locales/de.yml +40 -37
- data/config/locales/en.yml +48 -39
- data/config/locales/es.yml +49 -0
- data/config/locales/fr.yml +49 -0
- data/config/locales/it.yml +76 -0
- data/config/locales/nl.yml +41 -46
- data/config/locales/pt-BR.yml +51 -0
- data/config/locales/tr.yml +49 -0
- data/config/routes.rb +32 -15
- data/db/default/users.rb +13 -6
- data/db/migrate/20140904000425_add_deleted_at_to_users.rb +6 -0
- data/db/migrate/20141002154641_add_confirmable_to_users.rb +7 -0
- data/lib/assets/javascripts/spree/backend/spree_auth.js.erb +1 -0
- data/lib/assets/javascripts/spree/frontend/spree_auth.js.erb +1 -0
- data/lib/assets/stylesheets/spree/backend/spree_auth.css.erb +3 -0
- data/lib/assets/stylesheets/spree/frontend/spree_auth.css.erb +3 -0
- data/lib/controllers/backend/spree/admin/admin_controller_decorator.rb +26 -0
- data/lib/controllers/backend/spree/admin/admin_orders_controller_decorator.rb +20 -0
- data/{app/controllers → lib/controllers/backend}/spree/admin/admin_resource_controller_decorator.rb +0 -0
- data/{app/controllers/spree/admin/admin_orders_controller_decorator.rb → lib/controllers/backend/spree/admin/orders/customer_details_controller_decorator.rb} +3 -2
- data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +42 -0
- data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +53 -0
- data/{app/controllers → lib/controllers/frontend}/spree/checkout_controller_decorator.rb +8 -15
- data/lib/controllers/frontend/spree/user_confirmations_controller.rb +14 -0
- data/{app/controllers → lib/controllers/frontend}/spree/user_passwords_controller.rb +10 -9
- data/{app/controllers → lib/controllers/frontend}/spree/user_registrations_controller.rb +18 -15
- data/lib/controllers/frontend/spree/user_sessions_controller.rb +46 -0
- data/{app/controllers → lib/controllers/frontend}/spree/users_controller.rb +13 -9
- data/lib/generators/spree/auth/install/install_generator.rb +26 -0
- data/lib/generators/spree/auth/install/templates/config/initializers/devise.rb +1 -0
- data/lib/spree/auth.rb +2 -1
- data/lib/spree/auth/devise.rb +7 -0
- data/lib/spree/auth/engine.rb +57 -2
- data/lib/spree/authentication_helpers.rb +1 -1
- data/lib/spree_auth_devise.rb +3 -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 +38 -0
- data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +33 -0
- data/lib/views/backend/spree/layouts/login.html.erb +25 -0
- data/lib/views/frontend/spree/checkout/_new_user.html.erb +20 -0
- data/lib/views/frontend/spree/checkout/registration.html.erb +27 -0
- data/{app/views → lib/views/frontend}/spree/shared/_flashes.html.erb +0 -0
- data/lib/views/frontend/spree/shared/_login.html.erb +18 -0
- data/lib/views/frontend/spree/shared/_login_bar.html.erb +6 -0
- data/lib/views/frontend/spree/shared/_user_form.html.erb +13 -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 +22 -0
- data/lib/views/frontend/spree/user_passwords/new.html.erb +21 -0
- data/lib/views/frontend/spree/user_registrations/new.html.erb +22 -0
- data/lib/views/frontend/spree/user_sessions/new.html.erb +20 -0
- data/lib/views/frontend/spree/users/edit.html.erb +17 -0
- data/lib/views/frontend/spree/users/show.html.erb +43 -0
- data/spec/controllers/spree/admin/orders_controller_spec.rb +14 -0
- data/spec/controllers/spree/checkout_controller_spec.rb +141 -0
- data/spec/controllers/spree/products_controller_spec.rb +21 -0
- data/spec/controllers/spree/user_passwords_controller_spec.rb +44 -0
- data/spec/controllers/spree/user_registrations_controller_spec.rb +13 -0
- data/spec/controllers/spree/user_sessions_controller_spec.rb +56 -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 +28 -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 +45 -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 +24 -0
- data/spec/features/checkout_spec.rb +160 -0
- data/spec/features/confirmation_spec.rb +28 -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 +54 -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 +58 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/ability.rb +15 -0
- data/spec/support/authentication_helpers.rb +14 -0
- data/spec/support/capybara.rb +7 -0
- data/spec/support/confirm_helpers.rb +11 -0
- data/spec/support/database_cleaner.rb +18 -0
- data/spec/support/email.rb +5 -0
- data/spec/support/factory_girl.rb +5 -0
- data/spec/support/spree.rb +26 -0
- data/spree_auth_devise.gemspec +48 -0
- metadata +441 -79
- data/app/assets/javascripts/admin/spree_auth.js +0 -1
- data/app/assets/javascripts/store/spree_auth.js +0 -1
- data/app/assets/stylesheets/admin/spree_auth.css +0 -3
- data/app/assets/stylesheets/store/spree_auth.css +0 -3
- data/app/controllers/spree/admin/admin_controller_decorator.rb +0 -7
- data/app/controllers/spree/admin/admin_users_controller_decorator.rb +0 -21
- data/app/controllers/spree/admin/users_controller.rb +0 -77
- data/app/controllers/spree/base_controller_decorator.rb +0 -18
- data/app/controllers/spree/orders_controller_decorator.rb +0 -15
- data/app/controllers/spree/user_sessions_controller.rb +0 -54
- data/app/helpers/spree/users_helper.rb +0 -15
- data/app/models/spree/current_order_decorator.rb +0 -12
- data/app/overrides/admin_tab.rb +0 -6
- data/app/overrides/auth_admin_login_navigation_bar.rb +0 -5
- data/app/overrides/auth_user_login_form.rb +0 -6
- data/app/views/spree/admin/users/_form.html.erb +0 -37
- data/app/views/spree/admin/users/edit.html.erb +0 -28
- data/app/views/spree/admin/users/index.html.erb +0 -53
- data/app/views/spree/admin/users/new.html.erb +0 -23
- data/app/views/spree/admin/users/show.html.erb +0 -21
- data/app/views/spree/layouts/admin/_login_nav.html.erb +0 -8
- data/app/views/spree/shared/_login.html.erb +0 -20
- data/app/views/spree/shared/_login_bar.html.erb +0 -6
- data/app/views/spree/shared/_user_form.html.erb +0 -17
- data/app/views/spree/user_mailer/reset_password_instructions.text.erb +0 -10
- data/app/views/spree/user_passwords/edit.html.erb +0 -15
- data/app/views/spree/user_passwords/new.html.erb +0 -15
- data/app/views/spree/user_registrations/new.html.erb +0 -22
- data/app/views/spree/user_sessions/authorization_failure.html.erb +0 -4
- data/app/views/spree/user_sessions/new.html.erb +0 -13
- data/app/views/spree/users/edit.html.erb +0 -11
- data/app/views/spree/users/show.html.erb +0 -43
- data/config/initializers/spree.rb +0 -1
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
feature 'Confirmation' do
|
4
|
+
before do
|
5
|
+
set_confirmable_option(true)
|
6
|
+
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) { set_confirmable_option(false) }
|
10
|
+
|
11
|
+
let!(:store) { create(:store) }
|
12
|
+
|
13
|
+
background do
|
14
|
+
ActionMailer::Base.default_url_options[:host] = 'http://example.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
scenario 'create a new user' do
|
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
|
+
expect(page).to have_text 'You have signed up successfully.'
|
26
|
+
expect(Spree::User.last.confirmed?).to be(false)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
RSpec.feature 'Orders', :js, type: :feature do
|
2
|
+
|
3
|
+
scenario 'allow a user to view their cart at any time' do
|
4
|
+
visit spree.cart_path
|
5
|
+
expect(page).to have_text 'Your cart is empty'
|
6
|
+
end
|
7
|
+
|
8
|
+
# regression test for spree/spree#1687
|
9
|
+
scenario 'merge incomplete orders from different sessions' do
|
10
|
+
skip %{
|
11
|
+
TODO: has been broken for ~2 months as of:
|
12
|
+
https://github.com/spree/spree_auth_devise/commit/3157b47b22c559817d34ec34024587d8aa6136dc
|
13
|
+
I dont think we can decode these sessions anymore since Rails 4 switched to encrypted cookies I believe devise stores session encrypted.
|
14
|
+
}
|
15
|
+
create(:product, name: 'RoR Mug')
|
16
|
+
create(:product, name: 'RoR Shirt')
|
17
|
+
|
18
|
+
user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
|
19
|
+
|
20
|
+
using_session('first') do
|
21
|
+
visit spree.root_path
|
22
|
+
|
23
|
+
click_link 'RoR Mug'
|
24
|
+
click_button 'Add To Cart'
|
25
|
+
|
26
|
+
visit spree.login_path
|
27
|
+
fill_in 'Email', with: user.email
|
28
|
+
fill_in 'Password', with: user.password
|
29
|
+
click_button 'Login'
|
30
|
+
|
31
|
+
click_link 'Cart'
|
32
|
+
expect(page).to have_text 'RoR Mug'
|
33
|
+
end
|
34
|
+
|
35
|
+
using_session('second') do
|
36
|
+
visit spree.root_path
|
37
|
+
|
38
|
+
click_link 'RoR Shirt'
|
39
|
+
click_button 'Add To Cart'
|
40
|
+
|
41
|
+
visit spree.login_path
|
42
|
+
fill_in 'Email', with: user.email
|
43
|
+
fill_in 'Password', with: user.password
|
44
|
+
click_button 'Login'
|
45
|
+
|
46
|
+
# Order should have been merged with first session
|
47
|
+
click_link 'Cart'
|
48
|
+
expect(page).to have_text 'RoR Mug'
|
49
|
+
expect(page).to have_text 'RoR Shirt'
|
50
|
+
end
|
51
|
+
|
52
|
+
using_session('first') do
|
53
|
+
visit spree.root_path
|
54
|
+
|
55
|
+
click_link 'Cart'
|
56
|
+
|
57
|
+
# Order should have been merged with second session
|
58
|
+
expect(page).to have_text 'RoR Mug'
|
59
|
+
expect(page).to have_text 'RoR Shirt'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
RSpec.feature '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 'allow 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.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.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,54 @@
|
|
1
|
+
RSpec.feature 'Sign In', type: :feature do
|
2
|
+
|
3
|
+
background do
|
4
|
+
@user = create(:user, email: 'email@person.com', password: 'secret', password_confirmation: 'secret')
|
5
|
+
visit spree.login_path
|
6
|
+
end
|
7
|
+
|
8
|
+
scenario 'ask user to sign in' do
|
9
|
+
visit spree.admin_path
|
10
|
+
expect(page).not_to have_text 'Authorization Failure'
|
11
|
+
end
|
12
|
+
|
13
|
+
scenario 'let a user sign in successfully' do
|
14
|
+
fill_in 'Email', with: @user.email
|
15
|
+
fill_in 'Password', with: @user.password
|
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 'show 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 'allow a user to access a restricted page after logging in' do
|
34
|
+
user = create(:admin_user, email: 'admin@person.com', password: 'password', password_confirmation: 'password')
|
35
|
+
visit spree.admin_path
|
36
|
+
|
37
|
+
fill_in 'Email', with: user.email
|
38
|
+
fill_in 'Password', with: user.password
|
39
|
+
click_button 'Login'
|
40
|
+
|
41
|
+
within '.user-menu' do
|
42
|
+
expect(page).to have_text 'admin@person.com'
|
43
|
+
end
|
44
|
+
expect(current_path).to eq '/admin/orders'
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should store the user previous location" do
|
48
|
+
visit spree.account_path
|
49
|
+
fill_in "Email", with: @user.email
|
50
|
+
fill_in "Password", with: @user.password
|
51
|
+
click_button "Login"
|
52
|
+
expect(current_path).to eq "/account"
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
RSpec.feature 'Sign Out', type: :feature do
|
2
|
+
|
3
|
+
given!(:user) do
|
4
|
+
create(:user,
|
5
|
+
email: 'email@person.com',
|
6
|
+
password: 'secret',
|
7
|
+
password_confirmation: 'secret')
|
8
|
+
end
|
9
|
+
|
10
|
+
background do
|
11
|
+
visit spree.login_path
|
12
|
+
fill_in 'Email', with: user.email
|
13
|
+
fill_in 'Password', with: user.password
|
14
|
+
# Regression test for #1257
|
15
|
+
check 'Remember me'
|
16
|
+
click_button 'Login'
|
17
|
+
end
|
18
|
+
|
19
|
+
scenario 'allow a signed in user to logout' do
|
20
|
+
click_link 'Logout'
|
21
|
+
visit spree.root_path
|
22
|
+
expect(page).to have_text 'Login'
|
23
|
+
expect(page).not_to have_text 'Logout'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
RSpec.feature 'Sign Up', type: :feature do
|
2
|
+
|
3
|
+
context 'with valid data' do
|
4
|
+
scenario 'create a new user' do
|
5
|
+
visit spree.signup_path
|
6
|
+
|
7
|
+
fill_in 'Email', with: 'email@person.com'
|
8
|
+
fill_in 'Password', with: 'password'
|
9
|
+
fill_in 'Password Confirmation', with: 'password'
|
10
|
+
click_button 'Create'
|
11
|
+
|
12
|
+
expect(page).to have_text 'You have signed up successfully.'
|
13
|
+
expect(Spree::User.count).to eq(1)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'with invalid data' do
|
18
|
+
scenario 'does not create a new user' do
|
19
|
+
visit spree.signup_path
|
20
|
+
|
21
|
+
fill_in 'Email', with: 'email@person.com'
|
22
|
+
fill_in 'Password', with: 'password'
|
23
|
+
fill_in 'Password Confirmation', with: ''
|
24
|
+
click_button 'Create'
|
25
|
+
|
26
|
+
expect(page).to have_css '#errorExplanation'
|
27
|
+
expect(Spree::User.count).to eq(0)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
RSpec.describe Spree::UserMailer, type: :mailer do
|
2
|
+
|
3
|
+
let!(:store) { create(:store) }
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
|
6
|
+
before do
|
7
|
+
user = create(:user)
|
8
|
+
Spree::UserMailer.reset_password_instructions(user, 'token goes here').deliver_later
|
9
|
+
@message = ActionMailer::Base.deliveries.last
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#reset_password_instructions' do
|
13
|
+
describe 'message contents' do
|
14
|
+
before do
|
15
|
+
described_class.reset_password_instructions(user, 'token goes here').deliver_later
|
16
|
+
@message = ActionMailer::Base.deliveries.last
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'subject includes' do
|
20
|
+
it 'translated devise instructions' do
|
21
|
+
expect(@message.subject).to include(
|
22
|
+
I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'Spree site name' do
|
27
|
+
expect(@message.subject).to include store.name
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'body includes' do
|
32
|
+
it 'password reset url' do
|
33
|
+
expect(@message.body.raw_source).to include "http://#{store.url}/user/spree_user/password/edit"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'legacy support for User object' do
|
39
|
+
it 'sends an email' do
|
40
|
+
expect {
|
41
|
+
described_class.reset_password_instructions(user, 'token goes here').deliver_later
|
42
|
+
}.to change(ActionMailer::Base.deliveries, :size).by(1)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
RSpec.describe Spree::Order, type: :model do
|
2
|
+
|
3
|
+
let(:order) { described_class.new }
|
4
|
+
|
5
|
+
context '#associate_user!' do
|
6
|
+
let(:user) { build_stubbed(:user, email: 'spree@example.com') }
|
7
|
+
before { allow(order).to receive(:save!) { true } }
|
8
|
+
|
9
|
+
it 'associates the order with the specified user' do
|
10
|
+
order.associate_user! user
|
11
|
+
expect(order.user).to eq user
|
12
|
+
end
|
13
|
+
|
14
|
+
it "sets the order's email attribute to that of the specified user" do
|
15
|
+
order.associate_user! user
|
16
|
+
expect(order.email).to eq user.email
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'destroys any previous association with a guest user' do
|
20
|
+
guest_user = build_stubbed(:user)
|
21
|
+
order.user = guest_user
|
22
|
+
order.associate_user! user
|
23
|
+
expect(order.user).not_to eq guest_user
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
RSpec.describe Spree::User, type: :model do
|
2
|
+
|
3
|
+
before(:all) { Spree::Role.create name: 'admin' }
|
4
|
+
|
5
|
+
it '#admin?' do
|
6
|
+
expect(create(:admin_user).admin?).to be true
|
7
|
+
expect(create(:user).admin?).to be false
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'generates the reset password token' do
|
11
|
+
user = build(:user)
|
12
|
+
expect(Spree::UserMailer).to receive(:reset_password_instructions).with(user, anything, {}).and_return(double(deliver: true))
|
13
|
+
user.send_reset_password_instructions
|
14
|
+
expect(user.reset_password_token).not_to be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
context '#destroy' do
|
18
|
+
it 'will soft delete' do
|
19
|
+
order = build(:order, completed_at: Time.now)
|
20
|
+
order.save
|
21
|
+
user = order.user
|
22
|
+
user.destroy
|
23
|
+
expect(Spree::User.find_by_id(user.id)).to be_nil
|
24
|
+
expect(Spree::User.with_deleted.find_by_id(user.id).id).to eq(user.id)
|
25
|
+
expect(Spree::User.with_deleted.find_by_id(user.id).orders.first).to eq(order)
|
26
|
+
|
27
|
+
expect(Spree::Order.find_by_user_id(user.id)).not_to be_nil
|
28
|
+
expect(Spree::Order.where(user_id: user.id).first).to eq(order)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'will allow users to register later with same email address as previously deleted account' do
|
32
|
+
user1 = build(:user)
|
33
|
+
user1.save
|
34
|
+
|
35
|
+
user2 = build(:user)
|
36
|
+
user2.email = user1.email
|
37
|
+
expect(user2.save).to be false
|
38
|
+
expect(user2.errors.messages[:email].first).to eq "has already been taken"
|
39
|
+
|
40
|
+
user1.destroy
|
41
|
+
expect(user2.save).to be true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "confirmable" do
|
46
|
+
it "is confirmable if the confirmable option is enabled" do
|
47
|
+
set_confirmable_option(true)
|
48
|
+
Spree::UserMailer.stub(:confirmation_instructions).and_return(double(deliver: true))
|
49
|
+
expect(Spree::User.devise_modules).to include(:confirmable)
|
50
|
+
set_confirmable_option(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is not confirmable if the confirmable option is disabled" do
|
54
|
+
set_confirmable_option(false)
|
55
|
+
expect(Spree::User.devise_modules).to_not include(:confirmable)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start 'rails'
|
3
|
+
|
4
|
+
ENV['RAILS_ENV'] ||= 'test'
|
5
|
+
|
6
|
+
require File.expand_path('../dummy/config/environment', __FILE__)
|
7
|
+
|
8
|
+
require 'rspec/rails'
|
9
|
+
require 'shoulda-matchers'
|
10
|
+
require 'ffaker'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.filter_run focus: true
|
14
|
+
config.infer_spec_type_from_file_location!
|
15
|
+
config.raise_errors_for_deprecations!
|
16
|
+
config.run_all_when_everything_filtered = true
|
17
|
+
config.use_transactional_fixtures = false
|
18
|
+
|
19
|
+
config.mock_with :rspec do |mock|
|
20
|
+
mock.syntax = [:should, :expect]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
RSpec.configure do |config|
|
2
|
+
config.after do
|
3
|
+
Spree::Ability.abilities.delete(AbilityDecorator) if Spree::Ability.abilities.include?(AbilityDecorator)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
if defined? CanCan::Ability
|
8
|
+
class AbilityDecorator
|
9
|
+
include CanCan::Ability
|
10
|
+
|
11
|
+
def initialize(user)
|
12
|
+
cannot :manage, Spree::Order
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AuthenticationHelpers
|
2
|
+
def sign_in_as!(user)
|
3
|
+
visit '/login'
|
4
|
+
fill_in 'Email', with: user.email
|
5
|
+
fill_in 'Password', with: 'secret'
|
6
|
+
click_button 'Login'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.include AuthenticationHelpers, type: :feature
|
12
|
+
config.include Devise::TestHelpers, type: :controller
|
13
|
+
config.include Rack::Test::Methods, type: :feature
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module ConfirmHelpers
|
2
|
+
def set_confirmable_option(value)
|
3
|
+
Spree::Auth::Config[:confirmable] = value
|
4
|
+
Spree.send(:remove_const, 'User')
|
5
|
+
load File.expand_path("../../../app/models/spree/user.rb", __FILE__)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.configure do |c|
|
10
|
+
c.include ConfirmHelpers
|
11
|
+
end
|