Skip to content

Commit e6dface

Browse files
committed
Convert AuthenticationHelpers module to a patch
This way, we don't need to load ApplicationController in a config.to_prepare block either.
1 parent 15818b0 commit e6dface

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

.rubocop_todo.yml

-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Gemspec/OrderedDependencies:
2121
Layout/ArgumentAlignment:
2222
Exclude:
2323
- 'app/models/spree/user.rb'
24-
- 'lib/spree/authentication_helpers.rb'
2524
- 'spec/controllers/spree/user_sessions_controller_spec.rb'
2625
- 'spec/features/sign_out_spec.rb'
2726

@@ -351,7 +350,6 @@ Style/GuardClause:
351350
- 'db/migrate/20120203010234_add_reset_password_sent_at_to_spree_users.rb'
352351
- 'db/migrate/20190125170630_add_reset_password_token_index_to_spree_users.rb'
353352
- 'db/migrate/20200417153503_add_unconfirmed_email_to_spree_users.rb'
354-
- 'lib/spree/authentication_helpers.rb'
355353

356354
# Offense count: 1
357355
# This cop supports safe autocorrection (--autocorrect).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module SolidusAuthDevise
4+
module ApplicationControllerPatch
5+
def self.prepended(base)
6+
return unless base.respond_to?(:helper_method)
7+
8+
base.send(:helper_method, :spree_current_user)
9+
10+
return unless SolidusSupport.frontend_available?
11+
12+
base.send(:helper_method, :spree_login_path)
13+
base.send(:helper_method, :spree_signup_path)
14+
base.send(:helper_method, :spree_logout_path)
15+
end
16+
17+
def spree_current_user
18+
current_spree_user
19+
end
20+
21+
if SolidusSupport.frontend_available?
22+
delegate :login_path, :signup_path, :logout_path,
23+
to: :spree,
24+
prefix: :spree
25+
end
26+
27+
ApplicationController.prepend self
28+
end
29+
end

lib/solidus_auth_devise.rb

-2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,3 @@
1010
require 'solidus_auth_devise/configuration'
1111
require 'solidus_auth_devise/version'
1212
require 'solidus_auth_devise/engine'
13-
14-
require 'spree/authentication_helpers'

lib/spree/auth/engine.rb

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class Engine < Rails::Engine
2424
config.to_prepare do
2525
Spree::Auth::Engine.prepare_backend if SolidusSupport.backend_available?
2626
Spree::Auth::Engine.prepare_frontend if SolidusSupport.frontend_available?
27-
28-
ApplicationController.include Spree::AuthenticationHelpers
2927
end
3028

3129
def self.redirect_back_on_unauthorized?

lib/spree/authentication_helpers.rb

-27
This file was deleted.

0 commit comments

Comments
 (0)