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,17 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user } %>
2
+
3
+ <div id="forgot-password">
4
+ <h6><%= Spree.t(:forgot_password) %></h6>
5
+
6
+ <p><%= Spree.t(:instructions_to_reset_password) %></p>
7
+
8
+ <%= form_for Spree::User.new, :as => :spree_user, :url => spree.reset_password_path do |f| %>
9
+ <p>
10
+ <%= f.label :email, Spree.t(:email) %><br />
11
+ <%= f.email_field :email %>
12
+ </p>
13
+ <p>
14
+ <%= f.submit Spree.t(:reset_password), :class => 'button primary' %>
15
+ </p>
16
+ <% end %>
17
+ </div>
@@ -0,0 +1,4 @@
1
+ <div style="height:50px; padding-top:20px;">
2
+ <strong><%= Spree.t(:authorization_failure) %></strong>
3
+ </div>
4
+ <!-- Add your own custom access denied message here if you like -->
@@ -0,0 +1,31 @@
1
+ <% if flash[:alert] %>
2
+ <div class="flash errors"><%= flash[:alert] %></div>
3
+ <% end %>
4
+
5
+ <% @body_id = 'login' %>
6
+ <div id="existing-customer">
7
+ <h6><%= Spree.t(:admin_login) %></h6>
8
+ <div data-hook="login">
9
+ <%= form_for Spree::User.new, :as => :spree_user, :url => spree.admin_create_new_session_path do |f| %>
10
+ <div id="password-credentials">
11
+ <p>
12
+ <%= f.label :email, Spree.t(:email) %><br />
13
+ <%= f.email_field :email, :class => 'title', :tabindex => 1 %>
14
+ </p>
15
+ <p>
16
+ <%= f.label :password, Spree.t(:password) %><br />
17
+ <%= f.password_field :password, :class => 'title', :tabindex => 2 %>
18
+ </p>
19
+ </div>
20
+ <p>
21
+ <%= f.check_box :remember_me, :tabindex => 3 %>
22
+ <%= f.label :remember_me, Spree.t(:remember_me) %>
23
+ </p>
24
+
25
+ <p><%= f.submit Spree.t(:login), :class => 'button primary', :tabindex => 4 %></p>
26
+ <% end %>
27
+ <%= Spree.t(:or) %>
28
+ <%= link_to Spree.t(:forgot_password), spree.recover_password_path %>
29
+ </div>
30
+ </div>
31
+ <div data-hook="login_extras"></div>
@@ -0,0 +1,13 @@
1
+ <% if spree_current_user %>
2
+ <ul id="login-nav" class="inline-menu">
3
+ <li data-hook="user-logged-in-as"><%= Spree.t(:logged_in_as) %>: <%= spree_current_user.email %></li>
4
+ <li data-hook="user-account-link" class='fa fa-user'><%= link_to Spree.t(:account), spree.edit_user_path(spree_current_user) %></li>
5
+ <li data-hook="user-logout-link" class='fa fa-sign-out'><%= link_to Spree.t(:logout), spree.admin_logout_path %></li>
6
+
7
+ <% if spree.respond_to? :root_path %>
8
+ <li data-hook="store-frontend-link" class='fa fa-external-link'>
9
+ <%= link_to Spree.t(:back_to_store), spree.root_path, :target => '_blank' %>
10
+ </li>
11
+ <% end %>
12
+ </ul>
13
+ <% end %>
@@ -0,0 +1,22 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
2
+ <h1><%= Spree.t(:registration) %></h1>
3
+ <div id="registration" data-hook>
4
+ <div id="account" class="columns alpha eight">
5
+ <%= render template: 'spree/user_sessions/new' %>
6
+ </div>
7
+ <% if Spree::Config[:allow_guest_checkout] %>
8
+ <div id="guest_checkout" data-hook class="columns omega eight">
9
+ <h6><%= Spree.t(:guest_user_account) %></h6>
10
+ <% if flash[:registration_error] %>
11
+ <div class='flash error'><%= flash[:registration_error] %></div>
12
+ <% end %>
13
+ <%= form_for @order, :url => update_checkout_registration_path, :method => :put, :html => { :id => 'checkout_form_registration' } do |f| %>
14
+ <p>
15
+ <%= f.label :email, Spree.t(:email) %><br />
16
+ <%= f.email_field :email, :class => 'title' %>
17
+ </p>
18
+ <p><%= f.submit Spree.t(:continue), :class => 'button primary' %></p>
19
+ <% end %>
20
+ </div>
21
+ <% end %>
22
+ </div>
@@ -0,0 +1,9 @@
1
+ <% if flash.any? %>
2
+ <div id="flash">
3
+ <% flash.each do |key, value| %>
4
+ <p>
5
+ <%= value %>
6
+ </p>
7
+ <% end %>
8
+ </div>
9
+ <% end%>
@@ -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 => 'title', :tabindex => 1, autofocus: true %>
6
+ </p>
7
+ <p>
8
+ <%= f.label :password, Spree.t(:password) %><br />
9
+ <%= f.password_field :password, :class => 'title', :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 => 'button primary', :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,17 @@
1
+ <p>
2
+ <%= f.label :email, Spree.t(:email) %><br />
3
+ <%= f.email_field :email, :class => 'title' %>
4
+ </p>
5
+ <div id="password-credentials">
6
+ <p>
7
+ <%= f.label :password, Spree.t(:password) %><br />
8
+ <%= f.password_field :password, :class => 'title' %>
9
+ </p>
10
+
11
+ <p>
12
+ <%= f.label :password_confirmation, Spree.t(:confirm_password) %><br />
13
+ <%= f.password_field :password_confirmation, :class => 'title' %>
14
+ </p>
15
+ </div>
16
+
17
+ <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 link below:
4
+
5
+ <%= link_to 'Confirm my account', @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,17 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user } %>
2
+ <div id="change-password">
3
+ <h6><%= Spree.t(:change_my_password) %></h6>
4
+
5
+ <%= form_for @spree_user, :as => :spree_user, :url => spree.update_password_path, :method => :put do |f| %>
6
+ <p>
7
+ <%= f.label :password, Spree.t(:password) %><br />
8
+ <%= f.password_field :password %><br />
9
+ </p>
10
+ <p>
11
+ <%= f.label :password_confirmation, Spree.t(:confirm_password) %><br />
12
+ <%= f.password_field :password_confirmation %><br />
13
+ </p>
14
+ <%= f.hidden_field :reset_password_token %>
15
+ <%= f.submit Spree.t(:update), :class => 'button primary' %>
16
+ <% end %>
17
+ </div>
@@ -0,0 +1,17 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @spree_user } %>
2
+
3
+ <div id="forgot-password">
4
+ <h6><%= Spree.t(:forgot_password) %></h6>
5
+
6
+ <p><%= Spree.t(:instructions_to_reset_password) %></p>
7
+
8
+ <%= form_for Spree::User.new, :as => :spree_user, :url => spree.reset_password_path do |f| %>
9
+ <p>
10
+ <%= f.label :email, Spree.t(:email) %><br />
11
+ <%= f.email_field :email %>
12
+ </p>
13
+ <p>
14
+ <%= f.submit Spree.t(:reset_password), :class => 'button primary' %>
15
+ </p>
16
+ <% end %>
17
+ </div>
@@ -0,0 +1,21 @@
1
+ <% @body_id = 'signup' %>
2
+
3
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
4
+
5
+ <div id="new-customer">
6
+ <h6><%= Spree.t(:new_customer) %></h6>
7
+
8
+ <div data-hook="signup">
9
+ <%= form_for resource, :as => :spree_user, :url => spree.registration_path(@user) 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 => 'button primary' %></p>
13
+ </div>
14
+ <% end %>
15
+ <%= Spree.t(:or) %>&nbsp;<%= link_to Spree.t(:login_as_existing), spree.login_path %>
16
+
17
+ </div>
18
+
19
+ </div>
20
+
21
+ <div data-hook="login_extras"></div>
@@ -0,0 +1,4 @@
1
+ <div style="height:50px; padding-top:20px;">
2
+ <strong><%= Spree.t(:authorization_failure) %></strong>
3
+ </div>
4
+ <!-- Add your own custom access denied message here if you like -->
@@ -0,0 +1,13 @@
1
+ <% if flash[:alert] %>
2
+ <div class="flash errors"><%= flash[:alert] %></div>
3
+ <% end %>
4
+
5
+ <% @body_id = 'login' %>
6
+ <div id="existing-customer">
7
+ <h6><%= Spree.t(:login_as_existing) %></h6>
8
+ <div data-hook="login">
9
+ <%= render :partial => 'spree/shared/login' %>
10
+ <%= Spree.t(:or) %>&nbsp;<%= link_to Spree.t(:create_a_new_account), spree.signup_path %> | <%= link_to Spree.t(:forgot_password), spree.recover_password_path %>
11
+ </div>
12
+ </div>
13
+ <div data-hook="login_extras"></div>
@@ -0,0 +1,14 @@
1
+ <%= render :partial => 'spree/shared/error_messages', :locals => { :target => @user } %>
2
+
3
+ <div id="edit-account">
4
+ <h1><%= Spree.t(:editing_user) %></h1>
5
+
6
+ <div data-hook="account_edit">
7
+ <%= form_for Spree::User.new, :as => @user, :url => spree.user_path(@user), :method => :put do |f| %>
8
+ <%= render :partial => 'spree/shared/user_form', :locals => { :f => f } %>
9
+ <p>
10
+ <%= f.submit Spree.t(:update), :class => 'button primary' %>
11
+ </p>
12
+ <% end %>
13
+ </div>
14
+ </div>
@@ -0,0 +1,43 @@
1
+ <h1><%= accurate_title %></h1>
2
+
3
+ <div data-hook="account_summary" class="account-summary">
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="order-summary">
15
+ <thead>
16
+ <tr>
17
+ <th class="order-number"><%= I18n.t(:number, :scope => 'activerecord.attributes.spree/order') %></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 class="<%= cycle('even', 'odd') %>">
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="order-total"><%= order.display_total %></td>
34
+ </tr>
35
+ <% end %>
36
+ </tbody>
37
+ </table>
38
+ <% else %>
39
+ <p><%= Spree.t(:you_have_no_orders_yet) %></p>
40
+ <% end %>
41
+ <br />
42
+
43
+ </div>
@@ -0,0 +1,42 @@
1
+ # encoding: UTF-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.platform = Gem::Platform::RUBY
5
+ s.name = "solidus_auth_devise"
6
+ s.version = "1.0.0"
7
+ s.summary = "Provides authentication and authorization services for use with Solidus by using Devise and CanCan."
8
+ s.description = s.summary
9
+
10
+ s.author = 'Solidus Team'
11
+ s.email = 'contact@solidus.io'
12
+
13
+ s.required_ruby_version = ">= 2.1"
14
+ s.license = %q{BSD-3}
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- spec/*`.split("\n")
18
+ s.require_path = "lib"
19
+ s.requirements << "none"
20
+
21
+ solidus_version = [">= 1.0.0.pre", "< 2"]
22
+
23
+ s.add_dependency "solidus_core", solidus_version
24
+ s.add_dependency "devise", "~> 3.2.3"
25
+ s.add_dependency "devise-encryptable", "0.1.2"
26
+
27
+ s.add_dependency "json"
28
+ s.add_dependency "multi_json"
29
+
30
+ s.add_development_dependency "solidus_backend", solidus_version
31
+ s.add_development_dependency "solidus_frontend", solidus_version
32
+ s.add_development_dependency "rspec-rails", "~> 3.0.0"
33
+ s.add_development_dependency "simplecov", "~> 0.9.0"
34
+ s.add_development_dependency "sqlite3"
35
+ s.add_development_dependency "sass-rails", "~> 4.0.0"
36
+ s.add_development_dependency "coffee-rails", "~> 4.0.0"
37
+ s.add_development_dependency "shoulda-matchers", "~> 2.6.2"
38
+ s.add_development_dependency "factory_girl", "~> 4.4"
39
+ s.add_development_dependency "capybara", "~> 2.4.1"
40
+ s.add_development_dependency "poltergeist", "~> 1.5"
41
+ s.add_development_dependency "database_cleaner", "~> 1.2.0"
42
+ end
@@ -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.edit_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_line_items, 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.token_order_path(order, 'ABC')
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