From e1b9dc860f89727f9c4569132e2502a6bea5b75d Mon Sep 17 00:00:00 2001 From: Dave Copeland Date: Sun, 1 Mar 2015 15:05:20 -0500 Subject: [PATCH] remove use of hide_action in favor of protected Rails 5 will [not have `hide_action` any longer](https://github.com/rails/rails/pull/18371/files), as the Rails convention is to not expose private or protected methods as actions, thus obviating the need for `hide_action`. Presumably, there is code inheriting from `DeviseController` that is calling these helpers, so they cannot be private, so protected seems to be the only way to get Devise working with Rails 5. --- app/controllers/devise_controller.rb | 7 +++---- test/controllers/internal_helpers_test.rb | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/devise_controller.rb b/app/controllers/devise_controller.rb index c8cb0b40..59ca55f6 100644 --- a/app/controllers/devise_controller.rb +++ b/app/controllers/devise_controller.rb @@ -6,12 +6,13 @@ class DeviseController < Devise.parent_controller.constantize helpers = %w(resource scope_name resource_name signed_in_resource resource_class resource_params devise_mapping) - hide_action(*helpers) helper_method(*helpers) prepend_before_filter :assert_is_devise_resource! respond_to :html if mimes_for_respond_to.empty? + protected + # Gets the actual resource stored in the instance variable def resource instance_variable_get(:"@#{resource_name}") @@ -38,6 +39,7 @@ class DeviseController < Devise.parent_controller.constantize @devise_mapping ||= request.env["devise.mapping"] end + # Override prefixes to consider the scoped view. # Notice we need to check for the request due to a bug in # Action Controller tests that forces _prefixes to be @@ -50,9 +52,6 @@ class DeviseController < Devise.parent_controller.constantize end end - hide_action :_prefixes - - protected # Checks whether it's a devise mapped resource or not. def assert_is_devise_resource! #:nodoc: diff --git a/test/controllers/internal_helpers_test.rb b/test/controllers/internal_helpers_test.rb index c13c9917..2ba50306 100644 --- a/test/controllers/internal_helpers_test.rb +++ b/test/controllers/internal_helpers_test.rb @@ -13,16 +13,16 @@ class HelpersTest < ActionController::TestCase end test 'get resource name from env' do - assert_equal :user, @controller.resource_name + assert_equal :user, @controller.send(:resource_name) end test 'get resource class from env' do - assert_equal User, @controller.resource_class + assert_equal User, @controller.send(:resource_class) end test 'get resource instance variable from env' do @controller.instance_variable_set(:@user, user = User.new) - assert_equal user, @controller.resource + assert_equal user, @controller.send(:resource) end test 'set resource instance variable from env' do @@ -80,7 +80,7 @@ class HelpersTest < ActionController::TestCase test 'signed in resource returns signed in resource for current scope' do @mock_warden.expects(:authenticate).with(scope: :user).returns(User.new) - assert_kind_of User, @controller.signed_in_resource + assert_kind_of User, @controller.send(:signed_in_resource) end test 'is a devise controller' do