Skip to content

Commit bda1950

Browse files
authored
Merge pull request #2460 from eugeneius/lazy_load_action_controller_test_case
Don't force ActionController::TestCase to load
2 parents 2170177 + bb43abd commit bda1950

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)