Skip to content

Commit e057d36

Browse files
committed
Less hacky test routes setup
1 parent fb06a46 commit e057d36

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

test/support/rails_app.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ class ActiveModelSerializers::RailsApplication < Rails::Application
1616
end
1717
ActiveModelSerializers::RailsApplication.initialize!
1818

19+
Rails.application.routes.draw do
20+
get ':controller(/:action(/:id))'
21+
get ':controller(/:action)'
22+
end
1923
module TestHelper
20-
Routes = ActionDispatch::Routing::RouteSet.new
21-
Routes.draw do
22-
get ':controller(/:action(/:id))'
23-
get ':controller(/:action)'
24+
Routes = Rails.application.routes
25+
module ControllerTests
26+
def setup
27+
super
28+
@routes = TestHelper::Routes
29+
end
2430
end
25-
26-
ActionController::Base.send :include, Routes.url_helpers
31+
end
32+
ActiveSupport.on_load(:action_controller) do
33+
include TestHelper::Routes.url_helpers
34+
ActionController::TestCase.send :include, TestHelper::ControllerTests
2735
end

test/support/test_case.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
ActionController::TestCase.class_eval do
2-
def setup
3-
@routes = TestHelper::Routes
4-
end
5-
62
# For Rails5
73
# https://github.com/rails/rails/commit/ca83436d1b3b6cedd1eca2259f65661e69b01909#diff-b9bbf56e85d3fe1999f16317f2751e76L17
84
def assigns(key = nil)

0 commit comments

Comments
 (0)