@@ -10,6 +10,9 @@ class LazyRouteSetTest < ActiveSupport::TestCase
10
10
setup :build_app
11
11
teardown :teardown_app
12
12
13
+ class UsersController < ActionController ::Base
14
+ end
15
+
13
16
test "app lazily loads routes when invoking url helpers" do
14
17
require "#{ app_path } /config/environment"
15
18
@@ -63,11 +66,11 @@ class LazyRouteSetTest < ActiveSupport::TestCase
63
66
64
67
@app = Rails . application
65
68
66
- assert_not_operator ( :users_path , :in? , app_url_helpers . methods )
67
- assert_equal "/users " , app_url_helpers . url_for (
68
- controller : :users , action : :index , only_path : true ,
69
+ assert_not_operator ( :products_path , :in? , app_url_helpers . methods )
70
+ assert_equal "/products " , app_url_helpers . url_for (
71
+ controller : :products , action : :index , only_path : true ,
69
72
)
70
- assert_operator ( :users_path , :in? , app_url_helpers . methods )
73
+ assert_operator ( :products_path , :in? , app_url_helpers . methods )
71
74
end
72
75
73
76
test "engine lazily loads routes when url_for is used" do
@@ -97,6 +100,15 @@ class MyRailtie < ::Rails::Railtie
97
100
assert_operator ( Rails . application . routes , :is_a? , Engine ::LazyRouteSet )
98
101
end
99
102
103
+ test "reloads routes when recognize_path is called" do
104
+ require "#{ app_path } /config/environment"
105
+
106
+ assert_equal (
107
+ { controller : "rails/engine/lazy_route_set_test/users" , action : "index" } ,
108
+ Rails . application . routes . recognize_path ( "/users" )
109
+ )
110
+ end
111
+
100
112
private
101
113
def build_app
102
114
super
@@ -110,7 +122,8 @@ class User < ActiveRecord::Base
110
122
Rails.application.routes.draw do
111
123
root to: proc { [200, {}, []] }
112
124
113
- resources(:users)
125
+ resources :products
126
+ resources :users, module: "rails/engine/lazy_route_set_test"
114
127
115
128
mount Plugin::Engine, at: "/plugin"
116
129
end
0 commit comments