Skip to content

Commit 98b90ad

Browse files
authored
Merge pull request #2464 from Shopify/0-9-stable-ac-test-case-lazy
[0.9 stable] Avoid loading ActionController::TestCase in production
2 parents df80ba6 + 39b538e commit 98b90ad

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
@@ -9,12 +9,22 @@
99
begin
1010
require 'action_controller'
1111
require 'action_controller/serialization'
12-
require 'action_controller/serialization_test_case'
1312

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

0 commit comments

Comments
 (0)