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.

Files changed (144) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +11 -0
  5. data/Gemfile +5 -0
  6. data/{LICENSE → LICENSE.md} +1 -1
  7. data/README.md +86 -10
  8. data/Rakefile +15 -0
  9. data/Versionfile +5 -0
  10. data/app/controllers/metal_decorator.rb +6 -0
  11. data/app/mailers/spree/user_mailer.rb +12 -5
  12. data/app/models/spree/auth_configuration.rb +1 -0
  13. data/app/models/spree/user.rb +17 -50
  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/circle.yml +11 -0
  17. data/config.ru +4 -0
  18. data/config/initializers/devise.rb +3 -8
  19. data/config/initializers/warden.rb +14 -0
  20. data/config/locales/de.yml +40 -37
  21. data/config/locales/en.yml +48 -39
  22. data/config/locales/es.yml +49 -0
  23. data/config/locales/fr.yml +49 -0
  24. data/config/locales/it.yml +76 -0
  25. data/config/locales/nl.yml +41 -46
  26. data/config/locales/pt-BR.yml +51 -0
  27. data/config/locales/tr.yml +49 -0
  28. data/config/routes.rb +32 -15
  29. data/db/default/users.rb +13 -6
  30. data/db/migrate/20140904000425_add_deleted_at_to_users.rb +6 -0
  31. data/db/migrate/20141002154641_add_confirmable_to_users.rb +7 -0
  32. data/lib/assets/javascripts/spree/backend/spree_auth.js.erb +1 -0
  33. data/lib/assets/javascripts/spree/frontend/spree_auth.js.erb +1 -0
  34. data/lib/assets/stylesheets/spree/backend/spree_auth.css.erb +3 -0
  35. data/lib/assets/stylesheets/spree/frontend/spree_auth.css.erb +3 -0
  36. data/lib/controllers/backend/spree/admin/admin_controller_decorator.rb +26 -0
  37. data/lib/controllers/backend/spree/admin/admin_orders_controller_decorator.rb +20 -0
  38. data/{app/controllers → lib/controllers/backend}/spree/admin/admin_resource_controller_decorator.rb +0 -0
  39. data/{app/controllers/spree/admin/admin_orders_controller_decorator.rb → lib/controllers/backend/spree/admin/orders/customer_details_controller_decorator.rb} +3 -2
  40. data/lib/controllers/backend/spree/admin/user_passwords_controller.rb +42 -0
  41. data/lib/controllers/backend/spree/admin/user_sessions_controller.rb +53 -0
  42. data/{app/controllers → lib/controllers/frontend}/spree/checkout_controller_decorator.rb +8 -15
  43. data/lib/controllers/frontend/spree/user_confirmations_controller.rb +14 -0
  44. data/{app/controllers → lib/controllers/frontend}/spree/user_passwords_controller.rb +10 -9
  45. data/{app/controllers → lib/controllers/frontend}/spree/user_registrations_controller.rb +18 -15
  46. data/lib/controllers/frontend/spree/user_sessions_controller.rb +46 -0
  47. data/{app/controllers → lib/controllers/frontend}/spree/users_controller.rb +13 -9
  48. data/lib/generators/spree/auth/install/install_generator.rb +26 -0
  49. data/lib/generators/spree/auth/install/templates/config/initializers/devise.rb +1 -0
  50. data/lib/spree/auth.rb +2 -1
  51. data/lib/spree/auth/devise.rb +7 -0
  52. data/lib/spree/auth/engine.rb +57 -2
  53. data/lib/spree/authentication_helpers.rb +1 -1
  54. data/lib/spree_auth_devise.rb +3 -0
  55. data/lib/views/backend/spree/admin/user_passwords/edit.html.erb +15 -0
  56. data/lib/views/backend/spree/admin/user_passwords/new.html.erb +17 -0
  57. data/lib/views/backend/spree/admin/user_sessions/authorization_failure.html.erb +4 -0
  58. data/lib/views/backend/spree/admin/user_sessions/new.html.erb +38 -0
  59. data/lib/views/backend/spree/layouts/admin/_login_nav.html.erb +33 -0
  60. data/lib/views/backend/spree/layouts/login.html.erb +25 -0
  61. data/lib/views/frontend/spree/checkout/_new_user.html.erb +20 -0
  62. data/lib/views/frontend/spree/checkout/registration.html.erb +27 -0
  63. data/{app/views → lib/views/frontend}/spree/shared/_flashes.html.erb +0 -0
  64. data/lib/views/frontend/spree/shared/_login.html.erb +18 -0
  65. data/lib/views/frontend/spree/shared/_login_bar.html.erb +6 -0
  66. data/lib/views/frontend/spree/shared/_user_form.html.erb +13 -0
  67. data/lib/views/frontend/spree/user_mailer/confirmation_instructions.text.erb +5 -0
  68. data/lib/views/frontend/spree/user_mailer/reset_password_instructions.text.erb +10 -0
  69. data/lib/views/frontend/spree/user_passwords/edit.html.erb +22 -0
  70. data/lib/views/frontend/spree/user_passwords/new.html.erb +21 -0
  71. data/lib/views/frontend/spree/user_registrations/new.html.erb +22 -0
  72. data/lib/views/frontend/spree/user_sessions/new.html.erb +20 -0
  73. data/lib/views/frontend/spree/users/edit.html.erb +17 -0
  74. data/lib/views/frontend/spree/users/show.html.erb +43 -0
  75. data/spec/controllers/spree/admin/orders_controller_spec.rb +14 -0
  76. data/spec/controllers/spree/checkout_controller_spec.rb +141 -0
  77. data/spec/controllers/spree/products_controller_spec.rb +21 -0
  78. data/spec/controllers/spree/user_passwords_controller_spec.rb +44 -0
  79. data/spec/controllers/spree/user_registrations_controller_spec.rb +13 -0
  80. data/spec/controllers/spree/user_sessions_controller_spec.rb +56 -0
  81. data/spec/controllers/spree/users_controller_spec.rb +38 -0
  82. data/spec/factories/confirmed_user.rb +7 -0
  83. data/spec/features/account_spec.rb +58 -0
  84. data/spec/features/admin/orders_spec.rb +28 -0
  85. data/spec/features/admin/password_reset_spec.rb +24 -0
  86. data/spec/features/admin/products_spec.rb +9 -0
  87. data/spec/features/admin/sign_in_spec.rb +45 -0
  88. data/spec/features/admin/sign_out_spec.rb +22 -0
  89. data/spec/features/admin_permissions_spec.rb +46 -0
  90. data/spec/features/change_email_spec.rb +24 -0
  91. data/spec/features/checkout_spec.rb +160 -0
  92. data/spec/features/confirmation_spec.rb +28 -0
  93. data/spec/features/order_spec.rb +62 -0
  94. data/spec/features/password_reset_spec.rb +24 -0
  95. data/spec/features/sign_in_spec.rb +54 -0
  96. data/spec/features/sign_out_spec.rb +25 -0
  97. data/spec/features/sign_up_spec.rb +30 -0
  98. data/spec/mailers/user_mailer_spec.rb +46 -0
  99. data/spec/models/order_spec.rb +26 -0
  100. data/spec/models/user_spec.rb +58 -0
  101. data/spec/spec_helper.rb +24 -0
  102. data/spec/support/ability.rb +15 -0
  103. data/spec/support/authentication_helpers.rb +14 -0
  104. data/spec/support/capybara.rb +7 -0
  105. data/spec/support/confirm_helpers.rb +11 -0
  106. data/spec/support/database_cleaner.rb +18 -0
  107. data/spec/support/email.rb +5 -0
  108. data/spec/support/factory_girl.rb +5 -0
  109. data/spec/support/spree.rb +26 -0
  110. data/spree_auth_devise.gemspec +48 -0
  111. metadata +441 -79
  112. data/app/assets/javascripts/admin/spree_auth.js +0 -1
  113. data/app/assets/javascripts/store/spree_auth.js +0 -1
  114. data/app/assets/stylesheets/admin/spree_auth.css +0 -3
  115. data/app/assets/stylesheets/store/spree_auth.css +0 -3
  116. data/app/controllers/spree/admin/admin_controller_decorator.rb +0 -7
  117. data/app/controllers/spree/admin/admin_users_controller_decorator.rb +0 -21
  118. data/app/controllers/spree/admin/users_controller.rb +0 -77
  119. data/app/controllers/spree/base_controller_decorator.rb +0 -18
  120. data/app/controllers/spree/orders_controller_decorator.rb +0 -15
  121. data/app/controllers/spree/user_sessions_controller.rb +0 -54
  122. data/app/helpers/spree/users_helper.rb +0 -15
  123. data/app/models/spree/current_order_decorator.rb +0 -12
  124. data/app/overrides/admin_tab.rb +0 -6
  125. data/app/overrides/auth_admin_login_navigation_bar.rb +0 -5
  126. data/app/overrides/auth_user_login_form.rb +0 -6
  127. data/app/views/spree/admin/users/_form.html.erb +0 -37
  128. data/app/views/spree/admin/users/edit.html.erb +0 -28
  129. data/app/views/spree/admin/users/index.html.erb +0 -53
  130. data/app/views/spree/admin/users/new.html.erb +0 -23
  131. data/app/views/spree/admin/users/show.html.erb +0 -21
  132. data/app/views/spree/layouts/admin/_login_nav.html.erb +0 -8
  133. data/app/views/spree/shared/_login.html.erb +0 -20
  134. data/app/views/spree/shared/_login_bar.html.erb +0 -6
  135. data/app/views/spree/shared/_user_form.html.erb +0 -17
  136. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +0 -10
  137. data/app/views/spree/user_passwords/edit.html.erb +0 -15
  138. data/app/views/spree/user_passwords/new.html.erb +0 -15
  139. data/app/views/spree/user_registrations/new.html.erb +0 -22
  140. data/app/views/spree/user_sessions/authorization_failure.html.erb +0 -4
  141. data/app/views/spree/user_sessions/new.html.erb +0 -13
  142. data/app/views/spree/users/edit.html.erb +0 -11
  143. data/app/views/spree/users/show.html.erb +0 -43
  144. data/config/initializers/spree.rb +0 -1
@@ -0,0 +1,18 @@
1
+ <%= form_for Spree::User.new, :as => :spree_user, :url => spree.create_new_session_path do |f| %>
2
+ <div id="password-credentials">
3
+ <p>
4
+ <%= f.label :email, Spree.t(:email) %><br />
5
+ <%= f.email_field :email, :class => 'form-control', :tabindex => 1, autofocus: true %>
6
+ </p>
7
+ <p>
8
+ <%= f.label :password, Spree.t(:password) %><br />
9
+ <%= f.password_field :password, :class => 'form-control', :tabindex => 2 %>
10
+ </p>
11
+ </div>
12
+ <p>
13
+ <%= f.check_box :remember_me, :tabindex => 3 %>
14
+ <%= f.label :remember_me, Spree.t(:remember_me) %>
15
+ </p>
16
+
17
+ <p><%= f.submit Spree.t(:login), :class => 'btn btn-lg btn-success btn-block', :tabindex => 4 %></p>
18
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <% if spree_current_user %>
2
+ <li><%= link_to Spree.t(:my_account), spree.account_path %></li>
3
+ <li><%= link_to Spree.t(:logout), spree.logout_path %></li>
4
+ <% else %>
5
+ <li id="link-to-login"><%= link_to Spree.t(:login), spree.login_path %></li>
6
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <fieldset id="password-credentials">
2
+ <div class="form-group">
3
+ <%= f.email_field :email, :class => 'form-control', :placeholder => Spree.t(:email) %>
4
+ </div>
5
+ <hr />
6
+ <div class="form-group">
7
+ <%= f.password_field :password, :class => 'form-control', :placeholder => Spree.t(:password) %>
8
+ </div>
9
+ <div class="form-group">
10
+ <%= f.password_field :password_confirmation, :class => 'form-control', :placeholder => Spree.t(:confirm_password) %>
11
+ </div>
12
+ </fieldset>
13
+ <div data-hook="signup_below_password_fields"></div>
@@ -0,0 +1,5 @@
1
+ Welcome <%= @email %>!
2
+
3
+ You can confirm your account email through the url below:
4
+
5
+ <%= @confirmation_url %>
@@ -0,0 +1,10 @@
1
+ A request to reset your password has been made.
2
+ If you did not make this request, simply ignore this email.
3
+
4
+ If you did make this request just click the link below:
5
+
6
+ <%= @edit_password_reset_url %>
7
+
8
+ If the above URL does not work try copying and pasting it into your browser.
9
+ If you continue to have problems please feel free to contact us.
10
+
@@ -0,0 +1,22 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user } %>
2
+ <div class="col-md-6 col-md-offset-3">
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading">
5
+ <h3 class="panel-title"><%= Spree.t(:change_your_password) %></h3>
6
+ </div>
7
+ <div class="panel-body">
8
+ <%= form_for @spree_user, :as => :spree_user, :url => spree.update_password_path, :method => :put do |f| %>
9
+ <p>
10
+ <%= f.label :password, Spree.t(:password) %><br />
11
+ <%= f.password_field :password, :class => "form-control" %><br />
12
+ </p>
13
+ <p>
14
+ <%= f.label :password_confirmation, Spree.t(:confirm_password) %><br />
15
+ <%= f.password_field :password_confirmation, :class => "form-control" %><br />
16
+ </p>
17
+ <%= f.hidden_field :reset_password_token %>
18
+ <%= f.submit Spree.t(:update), :class => 'btn btn-lg btn-success btn-block' %>
19
+ <% end %>
20
+ </div>
21
+ </div>
22
+ </div>
@@ -0,0 +1,21 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user } %>
2
+ <div class="col-md-6 col-md-offset-3" id="forgot-password">
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading">
5
+ <h3 class="panel-title"><%= Spree.t(:forgot_password) %></h3>
6
+ </div>
7
+ <div class="panel-body">
8
+ <p><%= Spree.t(:instructions_to_reset_password) %></p>
9
+
10
+ <%= form_for Spree::User.new, :as => :spree_user, :url => spree.reset_password_path do |f| %>
11
+ <p>
12
+ <%= f.label :email, Spree.t(:email) %><br />
13
+ <%= f.email_field :email, :class => "form-control" %>
14
+ </p>
15
+ <p>
16
+ <%= f.submit Spree.t(:reset_password), :class => 'btn btn-lg btn-success btn-block' %>
17
+ </p>
18
+ <% end %>
19
+ </div>
20
+ </div>
21
+ </div>
@@ -0,0 +1,22 @@
1
+ <% @body_id = 'signup' %>
2
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
3
+ <div class="col-md-6 col-md-offset-3">
4
+ <div class="panel panel-default">
5
+ <div class="panel-heading">
6
+ <h3 class="panel-title"><%= Spree.t(:new_customer) %></h3>
7
+ </div>
8
+ <div id="new-customer" class="panel-body" data-hook="login">
9
+ <%= form_for resource, :as => :spree_user, :url => spree.registration_path do |f| %>
10
+ <div data-hook="signup_inside_form">
11
+ <%= render :partial => 'spree/shared/user_form', :locals => { :f => f } %>
12
+ <p><%= f.submit Spree.t(:create), :class => 'btn btn-lg btn-success btn-block' %></p>
13
+ </div>
14
+ <% end %>
15
+ <div class="text-center">
16
+ <%= Spree.t(:or) %>
17
+ <%= link_to Spree.t(:login_as_existing), spree.login_path %>
18
+ </div>
19
+ <div data-hook="login_extras"></div>
20
+ </div>
21
+ </div>
22
+ </div>
@@ -0,0 +1,20 @@
1
+ <% @body_id = 'login' %>
2
+ <div class="col-md-6 <%= request.path == spree.login_path ? "col-md-offset-3" : "" %>">
3
+ <div class="panel panel-default">
4
+ <div class="panel-heading">
5
+ <h3 class="panel-title"><%= Spree.t(:login_as_existing) %></h3>
6
+ </div>
7
+ <div id="existing-customer" class="panel-body" data-hook="login">
8
+ <% if flash[:alert] %>
9
+ <div class="alert alert-danger"><%= flash[:alert] %></div>
10
+ <% end %>
11
+ <%= render :partial => 'spree/shared/login' %>
12
+ <div class="text-center">
13
+ <%= Spree.t(:or) %>
14
+ <%= link_to Spree.t(:create_a_new_account), spree.signup_path %> |
15
+ <%= link_to Spree.t(:forgot_password), spree.recover_password_path %>
16
+ </div>
17
+ <div data-hook="login_extras"></div>
18
+ </div>
19
+ </div>
20
+ </div>
@@ -0,0 +1,17 @@
1
+ <div class="col-md-6 col-md-offset-3">
2
+ <div class="panel panel-default">
3
+ <div class="panel-heading">
4
+ <h3 class="panel-title"><%= Spree.t(:editing_user) %></h3>
5
+ </div>
6
+ <div class="panel-body">
7
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
8
+
9
+ <%= form_for Spree::User.new, :as => @user, :url => spree.user_path(@user), :method => :put do |f| %>
10
+ <%= render :partial => 'spree/shared/user_form', :locals => { :f => f } %>
11
+ <p>
12
+ <%= f.submit Spree.t(:update), :class => 'btn btn-primary' %>
13
+ </p>
14
+ <% end %>
15
+ </div>
16
+ </div>
17
+ </div>
@@ -0,0 +1,43 @@
1
+ <h1><%= accurate_title %></h1>
2
+
3
+ <div data-hook="account_summary" class="account-summary well">
4
+ <dl id="user-info">
5
+ <dt><%= Spree.t(:email) %></dt>
6
+ <dd><%= @user.email %> (<%= link_to Spree.t(:edit), spree.edit_account_path %>)</dd>
7
+ </dl>
8
+ </div>
9
+
10
+ <div data-hook="account_my_orders" class="account-my-orders">
11
+
12
+ <h3><%= Spree.t(:my_orders) %></h3>
13
+ <% if @orders.present? %>
14
+ <table class="table table-striped order-summary">
15
+ <thead class="active">
16
+ <tr>
17
+ <th class="order-number"><%= Spree::Order.human_attribute_name(:number) %></th>
18
+ <th class="order-date"><%= Spree.t(:date) %></th>
19
+ <th class="order-status"><%= Spree.t(:status) %></th>
20
+ <th class="order-payment-state"><%= Spree.t(:payment_state) %></th>
21
+ <th class="order-shipment-state"><%= Spree.t(:shipment_state) %></th>
22
+ <th class="order-total"><%= Spree.t(:total) %></th>
23
+ </tr>
24
+ </thead>
25
+ <tbody>
26
+ <% @orders.each do |order| %>
27
+ <tr>
28
+ <td class="order-number"><%= link_to order.number, order_url(order) %></td>
29
+ <td class="order-date"><%= l order.completed_at.to_date %></td>
30
+ <td class="order-status"><%= Spree.t("order_state.#{order.state}").titleize %></td>
31
+ <td class="order-payment-state"><%= Spree.t("payment_states.#{order.payment_state}").titleize if order.payment_state %></td>
32
+ <td class="order-shipment-state"><%= Spree.t("shipment_states.#{order.shipment_state}").titleize if order.shipment_state %></td>
33
+ <td class="lead text-primary order-total"><%= order.display_total %></td>
34
+ </tr>
35
+ <% end %>
36
+ </tbody>
37
+ </table>
38
+ <% else %>
39
+ <div class="alert alert-info"><%= Spree.t(:you_have_no_orders_yet) %></div>
40
+ <% end %>
41
+ <br />
42
+
43
+ </div>
@@ -0,0 +1,14 @@
1
+ module Spree
2
+ module Admin
3
+ RSpec.describe OrdersController, type: :controller do
4
+ stub_authorization!
5
+
6
+ context '#authorize_admin' do
7
+ it 'grants access to users with an admin role' do
8
+ spree_get :new
9
+ expect(response).to redirect_to spree.cart_admin_order_path(Order.last)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,141 @@
1
+ RSpec.describe Spree::CheckoutController, type: :controller do
2
+
3
+ let(:order) { create(:order_with_totals, email: nil, user: nil) }
4
+ let(:user) { build(:user, spree_api_key: 'fake') }
5
+ let(:token) { 'some_token' }
6
+
7
+ before do
8
+ allow(controller).to receive(:current_order) { order }
9
+ allow(order).to receive(:confirmation_required?) { true }
10
+ end
11
+
12
+ context '#edit' do
13
+ context 'when registration step enabled' do
14
+ before do
15
+ allow(controller).to receive(:check_authorization)
16
+ Spree::Auth::Config.set(registration_step: true)
17
+ end
18
+
19
+ context 'when authenticated as registered user' do
20
+ before { allow(controller).to receive(:spree_current_user) { user } }
21
+
22
+ it 'proceeds to the first checkout step' do
23
+ spree_get :edit, { state: 'address' }
24
+ expect(response).to render_template :edit
25
+ end
26
+ end
27
+
28
+ context 'when authenticated as guest' do
29
+ it 'redirects to registration step' do
30
+ spree_get :edit, { state: 'address' }
31
+ expect(response).to redirect_to spree.checkout_registration_path
32
+ end
33
+ end
34
+ end
35
+
36
+ context 'when registration step disabled' do
37
+ before do
38
+ Spree::Auth::Config.set(registration_step: false)
39
+ allow(controller).to receive(:check_authorization)
40
+ end
41
+
42
+ context 'when authenticated as registered' do
43
+ before { allow(controller).to receive(:spree_current_user) { user } }
44
+
45
+ it 'proceeds to the first checkout step' do
46
+ spree_get :edit, { state: 'address' }
47
+ expect(response).to render_template :edit
48
+ end
49
+ end
50
+
51
+ context 'when authenticated as guest' do
52
+ it 'proceeds to the first checkout step' do
53
+ spree_get :edit, { state: 'address' }
54
+ expect(response).to render_template :edit
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ context '#update' do
61
+ context 'when in the confirm state' do
62
+ before do
63
+ order.update_column(:email, 'spree@example.com')
64
+ order.update_column(:state, 'confirm')
65
+
66
+ # So that the order can transition to complete successfully
67
+ allow(order).to receive(:payment_required?) { false }
68
+ end
69
+
70
+ context 'with a token' do
71
+ before { allow(order).to receive(:guest_token) { 'ABC' } }
72
+
73
+ it 'redirects to the tokenized order view' do
74
+ request.cookie_jar.signed[:guest_token] = 'ABC'
75
+ spree_post :update, { state: 'confirm' }
76
+ expect(response).to redirect_to spree.order_path(order)
77
+ expect(flash.notice).to eq Spree.t(:order_processed_successfully)
78
+ end
79
+ end
80
+
81
+ context 'with a registered user' do
82
+ before do
83
+ allow(controller).to receive(:spree_current_user) { user }
84
+ allow(order).to receive(:user) { user }
85
+ allow(order).to receive(:guest_token) { nil }
86
+ end
87
+
88
+ it 'redirects to the standard order view' do
89
+ spree_post :update, { state: 'confirm' }
90
+ expect(response).to redirect_to spree.order_path(order)
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ context '#registration' do
97
+ it 'does not check registration' do
98
+ allow(controller).to receive(:check_authorization)
99
+ expect(controller).not_to receive(:check_registration)
100
+ spree_get :registration
101
+ end
102
+
103
+ it 'checks if the user is authorized for :edit' do
104
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
105
+ request.cookie_jar.signed[:guest_token] = token
106
+ spree_get :registration, {}
107
+ end
108
+ end
109
+
110
+ context '#update_registration' do
111
+ let(:user) { build(:user) }
112
+
113
+ it 'does not check registration' do
114
+ controller.stub :check_authorization
115
+ order.stub update_attributes: true
116
+ controller.should_not_receive :check_registration
117
+ spree_put :update_registration, { order: { } }
118
+ end
119
+
120
+ it 'renders the registration view if unable to save' do
121
+ allow(controller).to receive(:check_authorization)
122
+ spree_put :update_registration, { order: { email: 'invalid' } }
123
+ expect(flash[:registration_error]).to eq I18n.t(:email_is_invalid, scope: [:errors, :messages])
124
+ expect(response).to render_template :registration
125
+ end
126
+
127
+ it 'redirects to the checkout_path after saving' do
128
+ allow(order).to receive(:update_attributes) { true }
129
+ allow(controller).to receive(:check_authorization)
130
+ spree_put :update_registration, { order: { email: 'jobs@spreecommerce.com' } }
131
+ expect(response).to redirect_to spree.checkout_path
132
+ end
133
+
134
+ it 'checks if the user is authorized for :edit' do
135
+ request.cookie_jar.signed[:guest_token] = token
136
+ allow(order).to receive(:update_attributes) { true }
137
+ expect(controller).to receive(:authorize!).with(:edit, order, token)
138
+ spree_put :update_registration, { order: { email: 'jobs@spreecommerce.com' } }
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.describe Spree::ProductsController, type: :controller do
2
+
3
+ let!(:product) { create(:product, available_on: 1.year.from_now) }
4
+ let!(:user) { build(:user, spree_api_key: 'fake') }
5
+
6
+ it 'allows admins to view non-active products' do
7
+ allow(controller).to receive(:before_save_new_order)
8
+ allow(controller).to receive(:spree_current_user) { user }
9
+ allow(user).to receive(:has_spree_role?) { true }
10
+ spree_get :show, id: product.to_param
11
+ expect(response.status).to eq(200)
12
+ end
13
+
14
+ it 'cannot view non-active products' do
15
+ allow(controller).to receive(:before_save_new_order)
16
+ allow(controller).to receive(:spree_current_user) { user }
17
+ allow(user).to receive(:has_spree_role?) { false }
18
+ spree_get :show, id: product.to_param
19
+ expect(response.status).to eq(404)
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ RSpec.describe Spree::UserPasswordsController, type: :controller do
2
+
3
+ let(:token) { 'some_token' }
4
+
5
+ before { @request.env['devise.mapping'] = Devise.mappings[:spree_user] }
6
+
7
+ describe 'GET edit' do
8
+ context 'when the user token has not been specified' do
9
+ it 'redirects to the new session path' do
10
+ spree_get :edit
11
+ expect(response).to redirect_to(
12
+ 'http://test.host/user/spree_user/sign_in'
13
+ )
14
+ end
15
+
16
+ it 'flashes an error' do
17
+ spree_get :edit
18
+ expect(flash[:alert]).to include(
19
+ "You can't access this page without coming from a password reset " +
20
+ 'email'
21
+ )
22
+ end
23
+ end
24
+
25
+ context 'when the user token has been specified' do
26
+ it 'does something' do
27
+ spree_get :edit, reset_password_token: token
28
+ expect(response.code).to eq('200')
29
+ end
30
+ end
31
+ end
32
+
33
+ context '#update' do
34
+ context 'when updating password with blank password' do
35
+ it 'shows error flash message, sets spree_user with token and re-displays password edit form' do
36
+ spree_put :update, { spree_user: { password: '', password_confirmation: '', reset_password_token: token } }
37
+ expect(assigns(:spree_user).kind_of?(Spree::User)).to eq true
38
+ expect(assigns(:spree_user).reset_password_token).to eq token
39
+ expect(flash[:error]).to eq I18n.t(:cannot_be_blank, scope: [:devise, :user_passwords, :spree_user])
40
+ expect(response).to render_template :edit
41
+ end
42
+ end
43
+ end
44
+ end