File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -34,16 +34,6 @@ def optimize_routes_generation?
34
34
Rails . application &.reload_routes_unless_loaded
35
35
super
36
36
end
37
-
38
- def polymorphic_url ( record_or_hash_or_array , options = { } )
39
- Rails . application &.reload_routes_unless_loaded
40
- super
41
- end
42
-
43
- def polymorphic_path ( record_or_hash_or_array , options = { } )
44
- Rails . application &.reload_routes_unless_loaded
45
- super
46
- end
47
37
end
48
38
49
39
def initialize ( config = DEFAULT_CONFIG )
@@ -68,6 +58,11 @@ def call(req)
68
58
super
69
59
end
70
60
61
+ def polymorphic_mappings
62
+ Rails . application &.reload_routes_unless_loaded
63
+ super
64
+ end
65
+
71
66
def draw ( &block )
72
67
Rails . application &.reload_routes_unless_loaded
73
68
super
Original file line number Diff line number Diff line change @@ -52,6 +52,26 @@ class UsersController < ActionController::Base
52
52
assert_equal ( 200 , response . first )
53
53
end
54
54
55
+ test "app lazily loads routes when polymorphic_url is called" do
56
+ app_file "test/integration/my_test.rb" , <<~RUBY
57
+ require "test_helper"
58
+
59
+ class MyTest < ActionDispatch::IntegrationTest
60
+ test "polymorphic_url works" do
61
+ puts polymorphic_url(Comment.new)
62
+ end
63
+ end
64
+ RUBY
65
+
66
+ app_file "app/models/comment.rb" , <<~RUBY
67
+ class Comment
68
+ end
69
+ RUBY
70
+
71
+ output = rails ( "test" , "test/integration/my_test.rb" )
72
+ assert_match ( "https://example.org" , output )
73
+ end
74
+
55
75
test "engine lazily loads routes when making a request" do
56
76
require "#{ app_path } /config/environment"
57
77
@@ -137,6 +157,7 @@ class User < ActiveRecord::Base
137
157
138
158
resources :products
139
159
resources :users, module: "rails/engine/lazy_route_set_test"
160
+ resolve("Comment") { "https://example.org" }
140
161
141
162
mount Plugin::Engine, at: "/plugin"
142
163
end
You can’t perform that action at this time.
0 commit comments