Skip to content

Commit bb43abd

Browse files
committed
Don't force ActionController::TestCase to load
Instead of referencing ActionController::TestCase directly during boot, we can use a lazy load hook to apply our mixins if it is loaded later. The action_controller_test_case load hook was added in Rails 5.1, and the run_once option was added in Rails 5.2. I've left the behaviour unchanged for older Rails versions where they're not available.
1 parent 2170177 commit bb43abd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/active_model_serializers/railtie.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ class Railtie < Rails::Railtie
4444
end
4545
# :nocov:
4646

47+
def extend_action_controller_test_case(&block)
48+
if Rails::VERSION::MAJOR >= 6 || Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR >= 2
49+
ActiveSupport.on_load(:action_controller_test_case, run_once: true, &block)
50+
else
51+
ActionController::TestCase.instance_eval(&block)
52+
end
53+
end
54+
4755
if Rails.env.test?
48-
ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Schema)
49-
ActionController::TestCase.send(:include, ActiveModelSerializers::Test::Serializer)
56+
extend_action_controller_test_case do
57+
include ActiveModelSerializers::Test::Schema
58+
include ActiveModelSerializers::Test::Serializer
59+
end
5060
end
5161
end
5262
end

0 commit comments

Comments
 (0)