Skip to content

Commit

Permalink
Avoid loading ActionController::TestCase in production
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
byroot committed Apr 9, 2024
1 parent 07da9d0 commit 39b538e
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 @@ -7,12 +7,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 39b538e

Please sign in to comment.