spree_auth_devise 4.1.1 → 4.2.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.

Potentially problematic release.


This version of spree_auth_devise might be problematic. Click here for more details.

Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +29 -23
  3. data/Appraisals +1 -1
  4. data/Gemfile +1 -1
  5. data/Rakefile +9 -3
  6. data/app/controllers/spree/api/v2/storefront/account_confirmations_controller.rb +20 -0
  7. data/app/controllers/spree/api/v2/storefront/passwords_controller.rb +35 -0
  8. data/app/controllers/spree/user_passwords_controller.rb +1 -1
  9. data/app/mailers/spree/user_mailer.rb +6 -2
  10. data/app/models/spree/user.rb +17 -0
  11. data/app/services/spree/account/create.rb +19 -0
  12. data/app/services/spree/account/update.rb +17 -0
  13. data/app/views/spree/user_mailer/confirmation_instructions.text.erb +3 -3
  14. data/app/views/spree/user_mailer/reset_password_instructions.text.erb +2 -7
  15. data/config/locales/de.yml +18 -0
  16. data/config/locales/en.yml +7 -2
  17. data/config/locales/zh-TW.yml +60 -0
  18. data/config/routes.rb +10 -0
  19. data/gemfiles/spree_4_1.gemfile +1 -1
  20. data/lib/controllers/api/spree/api/v2/storefront/account_controller_decorator.rb +41 -0
  21. data/lib/controllers/frontend/spree/users_controller.rb +1 -6
  22. data/lib/spree/auth/engine.rb +14 -1
  23. data/spec/controllers/spree/api/v2/storefront/passwords_controller_spec.rb +63 -0
  24. data/spec/features/admin/sign_in_spec.rb +8 -2
  25. data/spec/features/checkout_spec.rb +1 -1
  26. data/spec/features/sign_in_spec.rb +13 -7
  27. data/spec/features/sign_out_spec.rb +1 -3
  28. data/spec/mailers/user_mailer_spec.rb +2 -2
  29. data/spec/models/user_spec.rb +4 -2
  30. data/spec/requests/spree/api/v2/storefront/account_confirmation_spec.rb +48 -0
  31. data/spec/requests/spree/api/v2/storefront/account_spec.rb +101 -0
  32. data/spec/spec_helper.rb +7 -38
  33. data/spree_auth_devise.gemspec +3 -25
  34. metadata +20 -344
  35. data/spec/requests/spree/frontend/user_update_spec.rb +0 -42
  36. data/spec/support/add_to_cart.rb +0 -22
  37. data/spec/support/authentication_helpers.rb +0 -14
  38. data/spec/support/cache_helpers.rb +0 -5
  39. data/spec/support/capybara.rb +0 -23
  40. data/spec/support/database_cleaner.rb +0 -17
  41. data/spec/support/factory_girl.rb +0 -5
  42. data/spec/support/spree.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46ff8af21fa16c063b0f61f5993e37f93072587b1e663e58089b2ea0a028b51b
4
- data.tar.gz: 6d7fa7607dd17ff3b6c5231bd8295c5fef51ea7620e1e459d199b39b42649858
3
+ metadata.gz: 118d51e3f609cac9bc6a69453d96893824814d99a44e8be828741ebd410c9aa9
4
+ data.tar.gz: dcb44d6ef585b73b82665d12b04821e5f9d6393ef87626cbbd4091e060390365
5
5
  SHA512:
6
- metadata.gz: 1eefe313a0b7cd621e9192d483624541790292872576927da6089350aaa14352faa00e0b2dd8f36d2920b9faf4776cc5287df6c5308d2bce9111ec95228f26a1
7
- data.tar.gz: 3e941ccde2788291ec91709149786c03dab905cf142811186a43949c3ce6549b89306e8ceb7692070dbb1a7a92ef306ae0adc808d62bb18d1ad27404afbc24f0
6
+ metadata.gz: 0e3de0c4e4fd5adf202a9fa312f6025eaef63d9b61c8024703b418dc911d9dab405c76d3c25c6ed3f7e7d84f1bb867c2874a21e08dad903618c8632cf087531a
7
+ data.tar.gz: d650a6a697c44abba86562a2bc94b98ba117ce74a4a57f614f6e210690ea4f44f8e21f64aaf8a55458b8323b0e8686a48f3b313453337635aae8ffd2fe944dc3
data/.travis.yml CHANGED
@@ -1,38 +1,44 @@
1
- sudo: required
2
- dist: trusty
3
-
4
- script:
5
- - bundle exec rake test_app
6
- - bundle exec rake spec
1
+ os: linux
2
+ dist: bionic
7
3
 
8
4
  addons:
9
- chrome: stable
10
- postgresql: 9.4
5
+ apt:
6
+ sources:
7
+ - google-chrome
8
+ packages:
9
+ - google-chrome-stable
11
10
 
12
- env:
13
- - DB=mysql
14
- - DB=postgres
11
+ services:
12
+ - mysql
13
+ - postgresql
15
14
 
16
15
  language: ruby
17
16
 
18
17
  rvm:
19
- - 2.5.1
20
- # - 2.6.5
18
+ - 2.5
19
+ - 2.6
20
+
21
+ env:
22
+ - DB=mysql
23
+ - DB=postgres
21
24
 
22
25
  gemfile:
23
26
  - gemfiles/spree_4_1.gemfile
24
27
  - gemfiles/spree_master.gemfile
25
28
 
26
- matrix:
27
- allow_failures:
28
- - gemfile: gemfiles/spree_master.gemfile
29
+ jobs:
30
+ allow_failures:
31
+ - gemfile: gemfiles/spree_master.gemfile
29
32
 
30
33
  before_install:
31
- - gem update bundler
32
34
  - mysql -u root -e "GRANT ALL ON *.* TO 'travis'@'%';"
33
- - wget -N https://chromedriver.storage.googleapis.com/2.35/chromedriver_linux64.zip -P ~/
34
- - unzip ~/chromedriver_linux64.zip -d ~/
35
- - rm ~/chromedriver_linux64.zip
36
- - sudo mv -f ~/chromedriver /usr/local/share/
37
- - sudo chmod +x /usr/local/share/chromedriver
38
- - sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
35
+
36
+ before_script:
37
+ - CHROME_MAIN_VERSION=`google-chrome-stable --version | sed -E 's/(^Google Chrome |\.[0-9]+ )//g'`
38
+ - CHROMEDRIVER_VERSION=`curl -s "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_$CHROME_MAIN_VERSION"`
39
+ - curl "https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip" -O
40
+ - unzip chromedriver_linux64.zip -d ~/bin
41
+
42
+ script:
43
+ - bundle exec rake test_app
44
+ - bundle exec rake spec
data/Appraisals CHANGED
@@ -1,6 +1,6 @@
1
1
  appraise 'spree-4-1' do
2
2
  gem 'rails-controller-testing'
3
- gem 'spree', github: 'spree/spree', branch: 'master'
3
+ gem 'spree', '~> 4.1'
4
4
  end
5
5
 
6
6
  appraise 'spree-master' do
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'rails-controller-testing'
4
- gem 'spree', '~> 4.1.0'
4
+ gem 'spree', github: 'spree/spree', branch: 'master'
5
5
 
6
6
  gemspec
data/Rakefile CHANGED
@@ -2,14 +2,20 @@ require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
4
4
  require 'rspec/core/rake_task'
5
- require 'spree/testing_support/common_rake'
5
+ require 'spree/testing_support/extension_rake'
6
6
 
7
7
  RSpec::Core::RakeTask.new
8
8
 
9
- task default: :spec
9
+ task :default do
10
+ if Dir["spec/dummy"].empty?
11
+ Rake::Task[:test_app].invoke
12
+ Dir.chdir("../../")
13
+ end
14
+ Rake::Task[:spec].invoke
15
+ end
10
16
 
11
17
  desc 'Generates a dummy app for testing'
12
18
  task :test_app do
13
19
  ENV['LIB_NAME'] = 'spree/auth'
14
- Rake::Task['common:test_app'].invoke("Spree::User")
20
+ Rake::Task['extension:test_app'].invoke
15
21
  end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class AccountConfirmationsController < ::Spree::Api::V2::BaseController
6
+
7
+ def show
8
+ user = Spree.user_class.confirm_by_token(params[:id])
9
+
10
+ if user.errors.empty?
11
+ render json: { data: { state: user.respond_to?(:state) ? user.state : '' } }, status: :ok
12
+ else
13
+ render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ class PasswordsController < ::Spree::Api::V2::BaseController
6
+ include Spree::Core::ControllerHelpers::Store
7
+
8
+ def create
9
+ user = Spree.user_class.find_by(email: params[:user][:email])
10
+
11
+ if user&.send_reset_password_instructions(current_store)
12
+ head :ok
13
+ else
14
+ head :not_found
15
+ end
16
+ end
17
+
18
+ def update
19
+ user = Spree.user_class.reset_password_by_token(
20
+ password: params[:user][:password],
21
+ password_confirmation: params[:user][:password_confirmation],
22
+ reset_password_token: params[:id]
23
+ )
24
+
25
+ if user.errors.empty?
26
+ head :ok
27
+ else
28
+ render json: { error: user.errors.full_messages.to_sentence }, status: :unprocessable_entity
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -20,7 +20,7 @@ class Spree::UserPasswordsController < Devise::PasswordsController
20
20
  # respond_with resource, :location => spree.login_path
21
21
  #
22
22
  def create
23
- self.resource = resource_class.send_reset_password_instructions(params[resource_name])
23
+ self.resource = resource_class.send_reset_password_instructions(params[resource_name], current_store)
24
24
 
25
25
  if resource.errors.empty?
26
26
  set_flash_message(:notice, :send_instructions) if is_navigational_format?
@@ -1,9 +1,13 @@
1
1
  module Spree
2
2
  class UserMailer < BaseMailer
3
3
  def reset_password_instructions(user, token, *_args)
4
- @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: Spree::Store.current.url)
4
+ current_store_id = _args.inject(:merge)[:current_store_id]
5
+ @current_store = Spree::Store.find(current_store_id) || Spree::Store.current
6
+ @locale = @current_store.has_attribute?(:default_locale) ? @current_store.default_locale : I18n.default_locale
7
+ I18n.locale = @locale if @locale.present?
8
+ @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @current_store.url)
5
9
 
6
- mail to: user.email, from: from_address, subject: Spree::Store.current.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
10
+ mail to: user.email, from: from_address, subject: @current_store.name + ' ' + I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])
7
11
  end
8
12
 
9
13
  def confirmation_instructions(user, token, _opts = {})
@@ -27,6 +27,23 @@ module Spree
27
27
  has_spree_role?('admin')
28
28
  end
29
29
 
30
+ def self.send_reset_password_instructions(attributes={}, current_store)
31
+ recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)
32
+ recoverable.send_reset_password_instructions(current_store) if recoverable.persisted?
33
+ recoverable
34
+ end
35
+
36
+ def send_reset_password_instructions(current_store)
37
+ token = set_reset_password_token
38
+ send_reset_password_instructions_notification(token, current_store.id)
39
+
40
+ token
41
+ end
42
+
43
+ def send_reset_password_instructions_notification(token, current_store_id)
44
+ send_devise_notification(:reset_password_instructions, token, { current_store_id: current_store_id })
45
+ end
46
+
30
47
  protected
31
48
 
32
49
  def password_required?
@@ -0,0 +1,19 @@
1
+ module Spree
2
+ module Account
3
+ class Create
4
+ prepend Spree::ServiceModule::Base
5
+
6
+ def call(user_params: nil)
7
+ user_params ||= {}
8
+
9
+ user = Spree.user_class.new(user_params)
10
+
11
+ if user.save
12
+ success(user)
13
+ else
14
+ failure(user)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ module Account
3
+ class Update
4
+ prepend Spree::ServiceModule::Base
5
+
6
+ def call(user:, user_params: nil)
7
+ user_params ||= {}
8
+
9
+ if user.update(user_params)
10
+ success(user)
11
+ else
12
+ failure(user)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
- Welcome <%= @email %>!
1
+ <%= Spree.t('confirmation_instructions.welcome', email: @email) %>
2
2
 
3
- You can confirm your account email through the url below:
3
+ <%= Spree.t('confirmation_instructions.confirm') %>
4
4
 
5
- <%= @confirmation_url %>
5
+ <%= @confirmation_url %>
@@ -1,10 +1,5 @@
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:
1
+ <%= Spree.t('user_mailer.reset_password_instructions.instructions_1') %>
5
2
 
6
3
  <%= @edit_password_reset_url %>
7
4
 
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
-
5
+ <%= Spree.t('user_mailer.reset_password_instructions.instructions_2') %>
@@ -1,9 +1,23 @@
1
1
  ---
2
2
  de:
3
+ spree:
4
+ admin_login: Admin Login
5
+ change_your_password: Kennwort zurücksetzen
6
+ store_credits:
7
+ credit_balance: Saldo des Guthabens
8
+ user_mailer:
9
+ reset_password_instructions:
10
+ instructions_1: "Es wurde eine Anfrage zum Zurücksetzen Ihres Passworts gestellt.\nWenn Sie diese Anfrage nicht gestellt haben, ignorieren Sie diese E-Mail.\n\nWenn Sie diese Anfrage gestellt haben, klicken Sie bitte auf den folgenden Link:"
11
+ instructions_2: "Falls die obige URL nicht funktioniert, bitte URL kopieren und in Ihren Browser einfügen\nWenn Sie weiterhin Probleme haben, können Sie sich gerne an uns wenden."
12
+ confirmation_instructions:
13
+ welcome: "Schön, dass Sie hier sind %{email}"
14
+ confirm: "Sie können Ihre Konto-E-Mail-Adresse über die folgende URL bestätigen:"
3
15
  devise:
4
16
  confirmations:
5
17
  confirmed: Ihr Konto wurde erfolgreich aktiviert.
6
18
  send_instructions: 'In ein paar Minuten erhalten Sie eine E-Mail mit Anweisungen, um Ihr Konto zu aktivieren.'
19
+ spree_user:
20
+ already_confirmed: Ihre E-Mail wurde bereits bestätigt. Bitte versuchen Sie erneut, sich anzumelden.
7
21
  failure:
8
22
  inactive: Ihr Konto wurde noch nicht aktiviert.
9
23
  invalid: Ungültige E-Mail-Adresse oder Passwort.
@@ -28,16 +42,20 @@ de:
28
42
  user_passwords:
29
43
  spree_user:
30
44
  cannot_be_blank: Ihr Passwort darf nicht leer sein.
45
+ no_token: Sie können nicht auf diese Seite zugreifen, wenn Sie den Link aus einer E-Mail zum Zurücksetzen des Kennworts nicht verwenden. Wenn Sie den Link aus einer E-Mail zum Zurücksetzen des Passworts verwenden, stellen Sie bitte sicher, dass Sie die vollständige URL verwendet haben.
31
46
  send_instructions: In ein paar Minuten erhalten Sie eine E-Mail mit Anweisungen um Ihr Passwort zurücksetzen.
32
47
  updated: Ihr Passwort wurde erfolgreich geändert.
33
48
  user_registrations:
34
49
  destroyed: Ihr Konto wurde erfolgreich gelöscht. Auf Wiedersehen!
35
50
  inactive_signed_up: 'Sie haben sich erfolgreich registriert. Wir konnten Sie jedoch nicht anmelden, da Ihr Konto %{reason} ist.'
51
+ signed_up_but_unconfirmed: Eine Nachricht mit einem Bestätigungslink wurde an Ihre E-Mail-Adresse gesendet. Bitte folgen Sie dem Link, um Ihr Konto zu aktivieren.
36
52
  signed_up: Herzlich Willkommen! Sie haben sich erfolgreich registriert.
37
53
  updated: Sie haben Ihr Konto erfolgreich aktualisiert.
38
54
  user_sessions:
39
55
  signed_in: Erfolgreich angemeldet.
40
56
  signed_out: Erfolgreich abgemeldet.
57
+ already_signed_in: Bereits angemeldet.
58
+ already_signed_out: Bereits abgemeldet.
41
59
  errors:
42
60
  messages:
43
61
  already_confirmed: wurde bereits bestätigt
@@ -5,6 +5,13 @@ en:
5
5
  change_your_password: "Change your password"
6
6
  store_credits:
7
7
  credit_balance: Store Credit Balance
8
+ user_mailer:
9
+ reset_password_instructions:
10
+ instructions_1: "A request to reset your password has been made.\nIf you did not make this request, simply ignore this email.\n\nIf you did make this request just click the link below:"
11
+ instructions_2: "If the above URL does not work try copying and pasting it into your browser.\nIf you continue to have problems please feel free to contact us."
12
+ confirmation_instructions:
13
+ welcome: "Welcome %{email}!"
14
+ confirm: "You can confirm your account email through the url below:"
8
15
  devise:
9
16
  confirmations:
10
17
  confirmed: Your account was successfully confirmed. You are now signed in.
@@ -26,8 +33,6 @@ en:
26
33
  subject: Reset password instructions
27
34
  unlock_instructions:
28
35
  subject: Unlock Instructions
29
- confirmation_instructions:
30
- subject: Confirmation instructions
31
36
  oauth_callbacks:
32
37
  failure: 'Could not authorize you from %{kind} because %{reason}.'
33
38
  success: 'Successfully authorized from %{kind} account.'
@@ -0,0 +1,60 @@
1
+ ---
2
+ zh-TW:
3
+ spree:
4
+ admin_login: "管理員登入"
5
+ change_your_password: "更改密碼"
6
+ store_credits:
7
+ credit_balance: 商城購物金餘額
8
+ devise:
9
+ confirmations:
10
+ confirmed: 你的帳號已經確認完成,現在你已經登入網站了。
11
+ send_instructions: 你會在幾分鐘內收到一封帳號確認信來確認你的帳號。
12
+ spree_user:
13
+ already_confirmed: Email 已確認,請登入。
14
+ failure:
15
+ inactive: 你的帳號尚未啟用。
16
+ invalid: 帳號或密碼有誤。
17
+ invalid_token: 錯誤的認證代碼。
18
+ locked: 你的帳號已經被停權,請聯絡客服人員。
19
+ timeout: 你的登入已經逾時,請重新登入。
20
+ unauthenticated: 你需要登入來繼續。
21
+ unconfirmed: 你的帳號需要確認來繼續。
22
+ mailer:
23
+ confirmation_instructions:
24
+ subject: 帳號確認教學
25
+ reset_password_instructions:
26
+ subject: 重設密碼教學
27
+ unlock_instructions:
28
+ subject: 帳號解鎖教學
29
+ oauth_callbacks:
30
+ failure: '由於%{reason},無法透過%{kind}確認你的帳號。'
31
+ success: '成功的由%{kind}認證你的帳號。'
32
+ unlocks:
33
+ send_instructions: 你在幾分鐘後會收到一封 Email 教你如何解鎖帳號。
34
+ unlocked: 你的帳號已經解鎖,現在你已經登入網站了。
35
+ user_passwords:
36
+ spree_user:
37
+ cannot_be_blank: 密碼不能為空白。
38
+ no_token: "你只能透過重新設定密碼的 Email 內的連結來訪問此頁面。如果你真的是透過那封 Email 來此頁面,請確定你是透過完整的網址過來的。"
39
+ send_instructions: 你在幾分鐘後會收到一封 Email 教你如何更改密碼。
40
+ updated: 你的密碼已經更改成功,你已成功登入。
41
+ user_registrations:
42
+ destroyed: 再見!你的帳號已經被取消了,但我們希望能再服務你。
43
+ inactive_signed_up: '你已經成功註冊,但由於%{reason}的原因,導致帳號無法登入。'
44
+ signed_up_but_unconfirmed: 確認信件已經寄到您的信箱,請按照上面的教學完成您的註冊。
45
+ signed_up: 歡迎!你已經成功註冊了。
46
+ updated: 你的帳號已經成功更新。
47
+ user_sessions:
48
+ signed_in: 登入成功
49
+ signed_out: 登出成功
50
+ already_signed_in: 已經登入
51
+ already_signed_out: 已經登入
52
+ errors:
53
+ messages:
54
+ already_confirmed: 已確認
55
+ email_is_invalid: Email 不能為空值
56
+ not_found: 找不到
57
+ not_locked: 沒有被鎖住
58
+ not_saved:
59
+ one: '%{resource}由於以下的一個錯誤導致無法被儲存:'
60
+ other: '%{resource}由於以下的%{count}個錯誤導致無法被儲存:'
data/config/routes.rb CHANGED
@@ -44,4 +44,14 @@ Spree::Core::Engine.add_routes do
44
44
  get '/logout' => 'user_sessions#destroy', :as => :logout
45
45
  end
46
46
  end
47
+
48
+ namespace :api, defaults: { format: 'json' } do
49
+ namespace :v2 do
50
+ namespace :storefront do
51
+ resource :account, controller: :account, only: %i[show create update]
52
+ resources :account_confirmations, only: %i[show]
53
+ resources :passwords, controller: :passwords, only: %i[create update]
54
+ end
55
+ end
56
+ end
47
57
  end
@@ -3,6 +3,6 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails-controller-testing"
6
- gem "spree", github: "spree/spree", branch: "master"
6
+ gem "spree", "~> 4.1"
7
7
 
8
8
  gemspec path: "../"
@@ -0,0 +1,41 @@
1
+ module Spree
2
+ module Api
3
+ module V2
4
+ module Storefront
5
+ module AccountControllerDecorator
6
+ def self.prepended(base)
7
+ base.skip_before_action :require_spree_current_user, only: [:create]
8
+ end
9
+
10
+ def create
11
+ result = Spree::Account::Create.call(user_params: spree_user_params)
12
+
13
+ render_payload(result)
14
+ end
15
+
16
+ def update
17
+ result = Spree::Account::Update.call(user: spree_current_user, user_params: spree_user_params)
18
+
19
+ render_payload(result)
20
+ end
21
+
22
+ private
23
+
24
+ def render_payload(result)
25
+ if result.success?
26
+ render_serialized_payload { serialize_resource(result.value) }
27
+ else
28
+ render_error_payload(result.error)
29
+ end
30
+ end
31
+
32
+ def spree_user_params
33
+ params.require(:user).permit(Spree::PermittedAttributes.user_attributes)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ ::Spree::Api::V2::Storefront::AccountController.prepend(Spree::Api::V2::Storefront::AccountControllerDecorator)
@@ -1,18 +1,14 @@
1
1
  class Spree::UsersController < Spree::StoreController
2
2
  before_action :set_current_order, except: :show
3
+ prepend_before_action :load_object, only: [:show, :edit, :update]
3
4
  prepend_before_action :authorize_actions, only: :new
4
5
 
5
6
  include Spree::Core::ControllerHelpers
6
7
 
7
8
  def show
8
- load_object
9
9
  @orders = @user.orders.complete.order('completed_at desc')
10
10
  end
11
11
 
12
- def edit
13
- load_object
14
- end
15
-
16
12
  def create
17
13
  @user = Spree.user_class.new(user_params)
18
14
  if @user.save
@@ -28,7 +24,6 @@ class Spree::UsersController < Spree::StoreController
28
24
  end
29
25
 
30
26
  def update
31
- load_object
32
27
  if @user.update(user_params)
33
28
  if params[:user][:password].present?
34
29
  # this logic needed b/c devise wants to log us out after password changes
@@ -42,7 +42,12 @@ module Spree
42
42
  'lib/assets/javascripts/spree/frontend/spree_auth.js',
43
43
  'lib/assets/javascripts/spree/frontend/spree_auth.css'
44
44
  ]
45
- Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/*/*_decorator*.rb")) do |c|
45
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/frontend/**/*_decorator*.rb")) do |c|
46
+ Rails.configuration.cache_classes ? require(c) : load(c)
47
+ end
48
+ end
49
+ if Spree::Auth::Engine.api_available?
50
+ Dir.glob(File.join(File.dirname(__FILE__), "../../controllers/api/**/*_decorator*.rb")) do |c|
46
51
  Rails.configuration.cache_classes ? require(c) : load(c)
47
52
  end
48
53
  end
@@ -61,6 +66,10 @@ module Spree
61
66
  @@frontend_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Frontend::Engine')
62
67
  end
63
68
 
69
+ def self.api_available?
70
+ @@api_available ||= ::Rails::Engine.subclasses.map(&:instance).map{ |e| e.class.to_s }.include?('Spree::Api::Engine')
71
+ end
72
+
64
73
  if backend_available?
65
74
  paths["app/controllers"] << "lib/controllers/backend"
66
75
  paths["app/views"] << "lib/views/backend"
@@ -71,6 +80,10 @@ module Spree
71
80
  paths["app/views"] << "lib/views/frontend"
72
81
  end
73
82
 
83
+ if api_available?
84
+ paths["app/controllers"] << "lib/controllers/api"
85
+ end
86
+
74
87
  config.to_prepare &method(:activate).to_proc
75
88
  end
76
89
  end
@@ -0,0 +1,63 @@
1
+ RSpec.describe Spree::Api::V2::Storefront::PasswordsController, type: :controller do
2
+ let(:user) { create(:user) }
3
+ let(:password) { 'new_password' }
4
+ let(:store) { create(:store) }
5
+
6
+ describe 'POST create' do
7
+ before { post :create, params: params }
8
+
9
+ context 'when the user email has not been specified' do
10
+ let(:params) { { user: { email: '' } } }
11
+ it 'responds with not found status' do
12
+ expect(response.code).to eq('404')
13
+ end
14
+ end
15
+
16
+ context 'when the user email not found' do
17
+ let(:params) { { user: { email: 'dummy_email@example.com' } } }
18
+ it 'responds with not found status' do
19
+ expect(response.code).to eq('404')
20
+ end
21
+ end
22
+
23
+ context 'when the user email has been specified' do
24
+ let(:params) { { user: { email: user.email } } }
25
+ it_behaves_like 'returns 200 HTTP status'
26
+ end
27
+ end
28
+
29
+ describe 'PATCH update' do
30
+ before { patch :update, params: params }
31
+
32
+ context 'when updating password with blank password' do
33
+ let(:params) {
34
+ {
35
+ id: user.send_reset_password_instructions(Spree::Store.current),
36
+ user: {
37
+ password: '',
38
+ password_confirmation: ''
39
+ }
40
+ }
41
+ }
42
+
43
+ it 'responds with error' do
44
+ expect(response.code).to eq('422')
45
+ expect(JSON.parse(response.body)['error']).to eq("Password can't be blank")
46
+ end
47
+ end
48
+
49
+ context 'when updating password with specified password' do
50
+ let(:params) {
51
+ {
52
+ id: user.send_reset_password_instructions(Spree::Store.current),
53
+ user: {
54
+ password: password,
55
+ password_confirmation: password
56
+ }
57
+ }
58
+ }
59
+
60
+ it_behaves_like 'returns 200 HTTP status'
61
+ end
62
+ end
63
+ end
@@ -34,8 +34,14 @@ RSpec.feature 'Admin - Sign In', type: :feature do
34
34
  fill_in 'Email', with: user.email
35
35
  fill_in 'Password', with: 'secret'
36
36
  click_button 'Log in'
37
- within '.user-menu' do
38
- expect(page).to have_text 'admin@person.com'
37
+ if Spree.version.to_f > 4.1
38
+ within '.navbar .dropdown-menu' do
39
+ expect(page).to have_text 'admin@person.com'
40
+ end
41
+ else
42
+ within '.user-menu' do
43
+ expect(page).to have_text 'admin@person.com'
44
+ end
39
45
  end
40
46
  expect(current_path).to eq '/admin/orders'
41
47
  end
@@ -60,7 +60,7 @@ RSpec.feature 'Checkout', :js, type: :feature do
60
60
  find('a.cart-icon').click
61
61
 
62
62
  expect(page).to have_text 'RoR Mug'
63
- within('h1') { expect(page).to have_text 'YOUR SHOPPING BAG' }
63
+ within('h1') { expect(page).to have_text 'YOUR SHOPPING CART' }
64
64
 
65
65
  click_link 'checkout'
66
66