Wrap helper_method calls in respond_to?(:helper_method)

This commit is contained in:
Ryan Mitchell
2015-08-29 05:29:05 -04:00
parent 40258bf100
commit a3da40a701
2 changed files with 30 additions and 3 deletions

View File

@@ -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

View 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