Skip to content

Commit 39b538e

Browse files
committed
Avoid loading ActionController::TestCase in production
Ref: Shopify#3 > By referencing that object, it brings in all of the patches defined > in `ActionController::TestCase` to the development and production > environment, including behaviours like disabling the threading > implementation of `ActionController::Live`
1 parent 07da9d0 commit 39b538e

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ jobs:
7575
bundle exec rake
7676
env:
7777
RAILS_VERSION: ${{ matrix.rails-version }}
78+
RAILS_ENV: test

lib/active_model_serializers.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@
77
begin
88
require 'action_controller'
99
require 'action_controller/serialization'
10-
require 'action_controller/serialization_test_case'
1110

1211
ActiveSupport.on_load(:action_controller) do
1312
if ::ActionController::Serialization.enabled
1413
ActionController::Base.send(:include, ::ActionController::Serialization)
15-
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
14+
15+
# action_controller_test_case load hook was added in Rails 5.1
16+
# https://github.com/rails/rails/commit/0510208dd1ff23baa619884c0abcae4d141fae53
17+
if ActiveSupport::VERSION::STRING < '5.1'
18+
require 'action_controller/serialization_test_case'
19+
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
20+
else
21+
ActiveSupport.on_load(:action_controller_test_case) do
22+
require 'action_controller/serialization_test_case'
23+
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
24+
end
25+
end
1626
end
1727
end
1828
rescue LoadError

0 commit comments

Comments
 (0)