Skip to content

Commit

Permalink
Move RouteTranslator::TestCase in its own file
Browse files Browse the repository at this point in the history
Require TestCase only if test environment
Remove action_controller require in extensions/action_controller
  • Loading branch information
ericproulx committed Mar 2, 2020
1 parent 93b3713 commit 47c6c44
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
21 changes: 5 additions & 16 deletions lib/route_translator/extensions/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'action_controller'
require 'active_support/concern'

module RouteTranslator
Expand All @@ -21,22 +20,12 @@ def set_locale_from_url
I18n.locale = old_locale if locale_from_url
end
end

module TestCase
extend ActiveSupport::Concern
include ActionController::UrlFor

included do
delegate :env, :request, to: :@controller
end

def _routes
@routes
end
end
end

ActiveSupport.on_load(:action_controller) do
ActionController::Base.include RouteTranslator::Controller
ActionController::TestCase.include RouteTranslator::TestCase if ENV['RAILS_ENV'] == 'test'
include RouteTranslator::Controller
if ENV['RAILS_ENV'] == 'test'
require 'route_translator/extensions/test_case'
ActionController::TestCase.include RouteTranslator::TestCase
end
end
18 changes: 18 additions & 0 deletions lib/route_translator/extensions/test_case.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require 'action_controller'

module RouteTranslator
module TestCase
extend ActiveSupport::Concern
include ActionController::UrlFor

included do
delegate :env, :request, to: :@controller
end

def _routes
@routes
end
end
end

0 comments on commit 47c6c44

Please sign in to comment.