solidus_auth_devise 1.0.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 (116) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.md +26 -0
  7. data/README.md +88 -0
  8. data/Rakefile +21 -0
  9. data/app/controllers/metal_decorator.rb +6 -0
  10. data/app/mailers/spree/user_mailer.rb +15 -0
  11. data/app/models/spree/auth_configuration.rb +7 -0
  12. data/app/models/spree/user.rb +50 -0
  13. data/app/overrides/auth_shared_login_bar.rb +7 -0
  14. data/app/overrides/spree/admin/shared/_header/auth_admin_login_navigation_bar.html.erb.deface +4 -0
  15. data/bin/rails +7 -0
  16. data/config/initializers/devise.rb +137 -0
  17. data/config/initializers/warden.rb +14 -0
  18. data/config/locales/de.yml +49 -0
  19. data/config/locales/en.yml +55 -0
  20. data/config/locales/es.yml +49 -0
  21. data/config/locales/fr.yml +49 -0
  22. data/config/locales/it.yml +76 -0
  23. data/config/locales/nl.yml +49 -0
  24. data/config/locales/pt-BR.yml +51 -0
  25. data/config/locales/tr.yml +49 -0
  26. data/config/routes.rb +48 -0
  27. data/db/default/users.rb +83 -0
  28. data/db/migrate/20101026184949_create_users.rb +29 -0
  29. data/db/migrate/20101026184950_rename_columns_for_devise.rb +37 -0
  30. data/db/migrate/20101214150824_convert_user_remember_field.rb +11 -0
  31. data/db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb +8 -0
  32. data/db/migrate/20120605211305_make_users_email_index_unique.rb +9 -0
  33. data/db/migrate/20140904000425_add_deleted_at_to_users.rb +6 -0
  34. data/db/migrate/20141002154641_add_confirmable_to_users.rb +7 -0
  35. data/db/seeds.rb +5 -0
  36. data/lib/assets/javascripts/spree/backend/solidus_auth.js +1 -0
  37. data/lib/assets/javascripts/spree/frontend/solidus_auth.js +1 -0
  38. data/lib/assets/stylesheets/spree/backend/solidus_auth.css +3 -0
  39. data/lib/assets/stylesheets/spree/frontend/solidus_auth.css +3 -0
  40. data/lib/controllers/backend/spree/admin/admin_controller_decorator.rb +26 -0
  41. data/lib/controllers/backend/spree/admin/admin_orders_controller_decorator.rb +20 -0
  42. data/lib/controllers/backend/spree/admin/admin_resource_controller_decorator.rb +3 -0
  43. data/lib/controllers/backend/spree/admin/orders/customer_details_controller_decorator.rb +15 -0
  44. data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +45 -0
  45. data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +47 -0
  46. data/lib/controllers/frontend/spree/checkout_controller_decorator.rb +47 -0
  47. data/lib/controllers/frontend/spree/user_confirmations_controller.rb +21 -0
  48. data/lib/controllers/frontend/spree/user_passwords_controller.rb +53 -0
  49. data/lib/controllers/frontend/spree/user_registrations_controller.rb +72 -0
  50. data/lib/controllers/frontend/spree/user_sessions_controller.rb +53 -0
  51. data/lib/controllers/frontend/spree/users_controller.rb +57 -0
  52. data/lib/generators/spree/auth/install/install_generator.rb +26 -0
  53. data/lib/generators/spree/auth/install/templates/config/initializers/devise.rb +1 -0
  54. data/lib/solidus/auth.rb +2 -0
  55. data/lib/solidus_auth_devise.rb +5 -0
  56. data/lib/spree/auth/devise.rb +20 -0
  57. data/lib/spree/auth/engine.rb +77 -0
  58. data/lib/spree/authentication_helpers.rb +26 -0
  59. data/lib/tasks/auth.rake +9 -0
  60. data/lib/views/backend/spree/admin/user_passwords/edit.html.erb +15 -0
  61. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +17 -0
  62. data/lib/views/backend/spree/admin/user_sessions/authorization_failure.html.erb +4 -0
  63. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +31 -0
  64. data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +13 -0
  65. data/lib/views/frontend/spree/checkout/registration.html.erb +22 -0
  66. data/lib/views/frontend/spree/shared/_flashes.html.erb +9 -0
  67. data/lib/views/frontend/spree/shared/_login.html.erb +18 -0
  68. data/lib/views/frontend/spree/shared/_login_bar.html.erb +6 -0
  69. data/lib/views/frontend/spree/shared/_user_form.html.erb +17 -0
  70. data/lib/views/frontend/spree/user_mailer/confirmation_instructions.text.erb +5 -0
  71. data/lib/views/frontend/spree/user_mailer/reset_password_instructions.text.erb +10 -0
  72. data/lib/views/frontend/spree/user_passwords/edit.html.erb +17 -0
  73. data/lib/views/frontend/spree/user_passwords/new.html.erb +17 -0
  74. data/lib/views/frontend/spree/user_registrations/new.html.erb +21 -0
  75. data/lib/views/frontend/spree/user_sessions/authorization_failure.html.erb +4 -0
  76. data/lib/views/frontend/spree/user_sessions/new.html.erb +13 -0
  77. data/lib/views/frontend/spree/users/edit.html.erb +14 -0
  78. data/lib/views/frontend/spree/users/show.html.erb +43 -0
  79. data/solidus_auth_devise.gemspec +42 -0
  80. data/spec/controllers/spree/admin/orders_controller_spec.rb +14 -0
  81. data/spec/controllers/spree/checkout_controller_spec.rb +141 -0
  82. data/spec/controllers/spree/products_controller_spec.rb +21 -0
  83. data/spec/controllers/spree/user_passwords_controller_spec.rb +44 -0
  84. data/spec/controllers/spree/user_registrations_controller_spec.rb +13 -0
  85. data/spec/controllers/spree/user_sessions_controller_spec.rb +56 -0
  86. data/spec/controllers/spree/users_controller_spec.rb +38 -0
  87. data/spec/factories/confirmed_user.rb +7 -0
  88. data/spec/features/account_spec.rb +58 -0
  89. data/spec/features/admin/orders_spec.rb +29 -0
  90. data/spec/features/admin/password_reset_spec.rb +24 -0
  91. data/spec/features/admin/payment_methods_spec.rb +16 -0
  92. data/spec/features/admin/products_spec.rb +9 -0
  93. data/spec/features/admin/sign_in_spec.rb +44 -0
  94. data/spec/features/admin/sign_out_spec.rb +22 -0
  95. data/spec/features/admin_permissions_spec.rb +46 -0
  96. data/spec/features/change_email_spec.rb +24 -0
  97. data/spec/features/checkout_spec.rb +165 -0
  98. data/spec/features/confirmation_spec.rb +28 -0
  99. data/spec/features/order_spec.rb +62 -0
  100. data/spec/features/password_reset_spec.rb +24 -0
  101. data/spec/features/sign_in_spec.rb +52 -0
  102. data/spec/features/sign_out_spec.rb +25 -0
  103. data/spec/features/sign_up_spec.rb +30 -0
  104. data/spec/mailers/user_mailer_spec.rb +46 -0
  105. data/spec/models/order_spec.rb +26 -0
  106. data/spec/models/user_spec.rb +58 -0
  107. data/spec/spec_helper.rb +25 -0
  108. data/spec/support/ability.rb +15 -0
  109. data/spec/support/authentication_helpers.rb +14 -0
  110. data/spec/support/capybara.rb +7 -0
  111. data/spec/support/confirm_helpers.rb +11 -0
  112. data/spec/support/database_cleaner.rb +18 -0
  113. data/spec/support/email.rb +5 -0
  114. data/spec/support/factory_girl.rb +5 -0
  115. data/spec/support/spree.rb +26 -0
  116. metadata +452 -0
@@ -0,0 +1,24 @@
1
+ RSpec.feature 'Change email', type: :feature do
2
+
3
+ background do
4
+ user = create(:user)
5
+ visit spree.root_path
6
+ click_link 'Login'
7
+
8
+ fill_in 'spree_user[email]', with: user.email
9
+ fill_in 'spree_user[password]', with: 'secret'
10
+ click_button 'Login'
11
+
12
+ visit spree.edit_account_path
13
+ end
14
+
15
+ scenario 'work with correct password' do
16
+ fill_in 'user_email', with: 'tests@example.com'
17
+ fill_in 'user_password', with: 'password'
18
+ fill_in 'user_password_confirmation', with: 'password'
19
+ click_button 'Update'
20
+
21
+ expect(page).to have_text 'Account updated'
22
+ expect(page).to have_text 'tests@example.com'
23
+ end
24
+ end
@@ -0,0 +1,165 @@
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
+
15
+ background do
16
+ @product = create(:product, name: 'RoR Mug')
17
+ @product.master.stock_items.first.update_column(:count_on_hand, 1)
18
+
19
+ # Bypass gateway error on checkout | ..or stub a gateway
20
+ Spree::Config[:allow_checkout_on_gateway_error] = true
21
+
22
+ visit spree.root_path
23
+ end
24
+
25
+ context 'without payment being required' do
26
+ background do
27
+ # So that we don't have to setup payment methods just for the sake of it
28
+ allow_any_instance_of(Spree::Order).to receive(:has_available_payment).and_return(true)
29
+ allow_any_instance_of(Spree::Order).to receive(:payment_required?).and_return(false)
30
+ end
31
+
32
+ scenario 'allow a visitor to checkout as guest, without registration' do
33
+ Spree::Auth::Config.set(registration_step: true)
34
+ click_link 'RoR Mug'
35
+ click_button 'Add To Cart'
36
+ within('h1') { expect(page).to have_text 'Shopping Cart' }
37
+ click_button 'Checkout'
38
+
39
+ expect(page).to have_content(/Checkout as a Guest/i)
40
+
41
+ within('#guest_checkout') { fill_in 'Email', with: 'spree@test.com' }
42
+ click_button 'Continue'
43
+
44
+ expect(page).to have_text(/Billing Address/i)
45
+ expect(page).to have_text(/Shipping Address/i)
46
+
47
+ str_addr = 'bill_address'
48
+ select 'United States', from: "order_#{str_addr}_attributes_country_id"
49
+ %w(firstname lastname address1 city zipcode phone).each do |field|
50
+ fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
51
+ end
52
+ select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
53
+ check 'order_use_billing'
54
+
55
+ click_button 'Save and Continue'
56
+ click_button 'Save and Continue'
57
+ click_button 'Place Order'
58
+
59
+ expect(page).to have_text 'Your order has been processed successfully'
60
+ end
61
+
62
+ scenario 'associate an uncompleted guest order with user after logging in' do
63
+ user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
64
+ click_link 'RoR Mug'
65
+ click_button 'Add To Cart'
66
+
67
+ visit spree.login_path
68
+ fill_in 'Email', with: user.email
69
+ fill_in 'Password', with: user.password
70
+ click_button 'Login'
71
+ click_link 'Cart'
72
+
73
+ expect(page).to have_text 'RoR Mug'
74
+ within('h1') { expect(page).to have_text 'Shopping Cart' }
75
+
76
+ click_button 'Checkout'
77
+
78
+ str_addr = 'bill_address'
79
+ select 'United States', from: "order_#{str_addr}_attributes_country_id"
80
+ %w(firstname lastname address1 city zipcode phone).each do |field|
81
+ fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
82
+ end
83
+ select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
84
+ check 'order_use_billing'
85
+
86
+ click_button 'Save and Continue'
87
+ click_button 'Save and Continue'
88
+ click_button 'Place Order'
89
+
90
+ expect(page).to have_text 'Your order has been processed successfully'
91
+ expect(Spree::Order.first.user).to eq user
92
+ end
93
+
94
+ # Regression test for #890
95
+ scenario 'associate an incomplete guest order with user after successful password reset' do
96
+ create(:store)
97
+ user = create(:user, email: 'email@person.com', password: 'password', password_confirmation: 'password')
98
+ click_link 'RoR Mug'
99
+ click_button 'Add To Cart'
100
+
101
+ visit spree.login_path
102
+ click_link 'Forgot Password?'
103
+ fill_in 'spree_user_email', with: 'email@person.com'
104
+ click_button 'Reset my password'
105
+
106
+ # Need to do this now because the token stored in the DB is the encrypted version
107
+ # The 'plain-text' version is sent in the email and there's one way to get that!
108
+ reset_password_email = ActionMailer::Base.deliveries.first
109
+ token_url_regex = /^http:\/\/www.example.com\/user\/spree_user\/password\/edit\?reset_password_token=(.*)$/
110
+ token = token_url_regex.match(reset_password_email.body.to_s)[1]
111
+
112
+ visit spree.edit_spree_user_password_path(reset_password_token: token)
113
+ fill_in 'Password', with: 'password'
114
+ fill_in 'Password Confirmation', with: 'password'
115
+ click_button 'Update'
116
+
117
+ click_link 'Cart'
118
+ click_button 'Checkout'
119
+
120
+ str_addr = 'bill_address'
121
+ select 'United States', from: "order_#{str_addr}_attributes_country_id"
122
+ %w(firstname lastname address1 city zipcode phone).each do |field|
123
+ fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
124
+ end
125
+ select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
126
+ check 'order_use_billing'
127
+
128
+ click_button 'Save and Continue'
129
+
130
+ expect(page).not_to have_text 'Email is invalid'
131
+ end
132
+
133
+ scenario 'allow a user to register during checkout' do
134
+ click_link 'RoR Mug'
135
+ click_button 'Add To Cart'
136
+ click_button 'Checkout'
137
+
138
+ expect(page).to have_text 'Registration'
139
+
140
+ click_link 'Create a new account'
141
+
142
+ fill_in 'Email', with: 'email@person.com'
143
+ fill_in 'Password', with: 'spree123'
144
+ fill_in 'Password Confirmation', with: 'spree123'
145
+ click_button 'Create'
146
+
147
+ expect(page).to have_text 'You have signed up successfully.'
148
+
149
+ str_addr = 'bill_address'
150
+ select 'United States', from: "order_#{str_addr}_attributes_country_id"
151
+ %w(firstname lastname address1 city zipcode phone).each do |field|
152
+ fill_in "order_#{str_addr}_attributes_#{field}", with: "#{address.send(field)}"
153
+ end
154
+ select "#{address.state.name}", from: "order_#{str_addr}_attributes_state_id"
155
+ check 'order_use_billing'
156
+
157
+ click_button 'Save and Continue'
158
+ click_button 'Save and Continue'
159
+ click_button 'Place Order'
160
+
161
+ expect(page).to have_text 'Your order has been processed successfully'
162
+ expect(Spree::Order.first.user).to eq Spree::User.find_by_email('email@person.com')
163
+ end
164
+ end
165
+ end
@@ -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,52 @@
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
+ expect(page).to have_text 'Logged in as: admin@person.com'
42
+ expect(current_path).to eq '/admin/orders'
43
+ end
44
+
45
+ it "should store the user previous location" do
46
+ visit spree.account_path
47
+ fill_in "Email", with: @user.email
48
+ fill_in "Password", with: @user.password
49
+ click_button "Login"
50
+ expect(current_path).to eq "/account"
51
+ end
52
+ 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
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
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
42
+ }.to change(ActionMailer::Base.deliveries, :size).by(1)
43
+ end
44
+ end
45
+ end
46
+ end