mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:08:05 -05:00
Wrap helper_method calls in respond_to?(:helper_method)
This commit is contained in:
@@ -7,7 +7,9 @@ module Devise
|
||||
include Devise::Controllers::StoreLocation
|
||||
|
||||
included do
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
if respond_to?(:helper_method)
|
||||
helper_method :warden, :signed_in?, :devise_controller?
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
@@ -69,7 +71,9 @@ module Devise
|
||||
end.compact
|
||||
end
|
||||
|
||||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
|
||||
if respond_to?(:helper_method)
|
||||
helper_method "current_#{group_name}", "current_#{group_name.to_s.pluralize}", "#{group_name}_signed_in?"
|
||||
end
|
||||
METHODS
|
||||
end
|
||||
|
||||
@@ -126,7 +130,9 @@ module Devise
|
||||
METHODS
|
||||
|
||||
ActiveSupport.on_load(:action_controller) do
|
||||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
||||
if respond_to?(:helper_method)
|
||||
helper_method "current_#{mapping}", "#{mapping}_signed_in?", "#{mapping}_session"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
21
test/controllers/helper_methods_test.rb
Normal file
21
test/controllers/helper_methods_test.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require 'test_helper'
|
||||
|
||||
class ApiController < ActionController::Metal
|
||||
include Devise::Controllers::Helpers
|
||||
end
|
||||
|
||||
class HelperMethodsTest < ActionController::TestCase
|
||||
tests ApiController
|
||||
|
||||
test 'includes Devise::Controllers::Helpers' do
|
||||
assert @controller.class.ancestors.include?(Devise::Controllers::Helpers)
|
||||
end
|
||||
|
||||
test 'does not respond_to helper_method' do
|
||||
refute @controller.respond_to?(:helper_method)
|
||||
end
|
||||
|
||||
test 'defines methods like current_user' do
|
||||
assert @controller.respond_to?(:current_user)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user