Skip to content

Commit

Permalink
Merge pull request #3732 from posgarou/refactor/respond_to_helper_method
Browse files Browse the repository at this point in the history
Wrap helper_method calls in respond_to?(:helper_method)
  • Loading branch information
lucasmazza committed Sep 26, 2015
2 parents 2ccffc8 + 04e01f4 commit 7df57d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/devise/controllers/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ module Helpers
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
Expand Down Expand Up @@ -69,7 +71,9 @@ def current_#{group_name.to_s.pluralize}
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

Expand Down Expand Up @@ -126,7 +130,9 @@ def #{mapping}_session
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

Expand Down
21 changes: 21 additions & 0 deletions test/controllers/helper_methods_test.rb
Original file line number Diff line number Diff line change
@@ -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_includes @controller.class.ancestors, Devise::Controllers::Helpers
end

test 'does not respond_to helper_method' do
refute_respond_to @controller.class, :helper_method
end

test 'defines methods like current_user' do
assert_respond_to @controller, :current_user
end
end

0 comments on commit 7df57d5

Please sign in to comment.