Testing Controller Load Hook Implementation in Devise
This test suite validates Devise’s controller load hooks functionality, ensuring proper method definition and execution during the controller loading process. It specifically tests the ActiveSupport load hook mechanism within Devise controllers.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
heartcombo/devise
test/controllers/load_hooks_controller_test.rb
# frozen_string_literal: true
require 'test_helper'
class LoadHooksControllerTest < Devise::ControllerTestCase
setup do
ActiveSupport.on_load(:devise_controller) do
define_method :defined_by_load_hook do
puts 'I am defined dynamically by activesupport load hook'
end
end
end
teardown do
DeviseController.class_eval { undef :defined_by_load_hook }
end
test 'load hook called when controller is loaded' do
assert_includes DeviseController.instance_methods, :defined_by_load_hook
end
end