Skip to content

Commit

Permalink
Merge pull request #2464 from Shopify/0-9-stable-ac-test-case-lazy
Browse files Browse the repository at this point in the history
[0.9 stable]  Avoid loading ActionController::TestCase in production
  • Loading branch information
byroot committed Apr 9, 2024
2 parents df80ba6 + 39b538e commit 98b90ad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ jobs:
bundle exec rake
env:
RAILS_VERSION: ${{ matrix.rails-version }}
RAILS_ENV: test
14 changes: 12 additions & 2 deletions lib/active_model_serializers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@
begin
require 'action_controller'
require 'action_controller/serialization'
require 'action_controller/serialization_test_case'

ActiveSupport.on_load(:action_controller) do
if ::ActionController::Serialization.enabled
ActionController::Base.send(:include, ::ActionController::Serialization)
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)

# action_controller_test_case load hook was added in Rails 5.1
# https://github.com/rails/rails/commit/0510208dd1ff23baa619884c0abcae4d141fae53
if ActiveSupport::VERSION::STRING < '5.1'
require 'action_controller/serialization_test_case'
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
else
ActiveSupport.on_load(:action_controller_test_case) do
require 'action_controller/serialization_test_case'
ActionController::TestCase.send(:include, ::ActionController::SerializationAssertions)
end
end
end
end
rescue LoadError
Expand Down

0 comments on commit 98b90ad

Please sign in to comment.