From f6c7be78b2296555fd135ff3d13dc296c11f7dae Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Wed, 21 Mar 2018 16:57:14 +0100 Subject: [PATCH] Fix overriding ActionController::Live Including ActionController::TestCase::Behavior overrides ActionController::Live#new_controller_thread. This issue also affects any production mode as the include is not done just in test mode. This pull request separates production code from test code by query the environment. In the future we should think about separating even more by monkey patching in tests only. Ref: rails/rails#31200 --- lib/route_translator/extensions/action_controller.rb | 2 +- lib/route_translator/translator/route_helpers.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/route_translator/extensions/action_controller.rb b/lib/route_translator/extensions/action_controller.rb index b0359ac4..6926d24d 100644 --- a/lib/route_translator/extensions/action_controller.rb +++ b/lib/route_translator/extensions/action_controller.rb @@ -42,5 +42,5 @@ def _routes ActiveSupport.on_load(:action_controller) do ActionController::Base.send :include, RouteTranslator::Controller - ActionController::TestCase.send :include, RouteTranslator::TestCase + ActionController::TestCase.send :include, RouteTranslator::TestCase if ENV['RAILS_ENV'] == 'test' end diff --git a/lib/route_translator/translator/route_helpers.rb b/lib/route_translator/translator/route_helpers.rb index 5a6e90d7..51779219 100644 --- a/lib/route_translator/translator/route_helpers.rb +++ b/lib/route_translator/translator/route_helpers.rb @@ -34,7 +34,7 @@ def add(old_name, named_route_collection) __send__(Translator.route_name_for(args, old_name, suffix, self), *args) end - add_helpers_to_test_cases(helper_container) + add_helpers_to_test_cases(helper_container) if ENV['RAILS_ENV'] == 'test' end end end