Skip to content

Commit 14112a8

Browse files
authored
Bugfix and regressiontest for Engine.routes (#932)
* RouteSet `def url_helpers` modelled after: >>> Rails.application.routes.method(:url_helpers).source_location ``` ["/usr/local/bundle/gems/actionpack-6.0.6.1/lib/action_dispatch/routing/route_set.rb", 478] ``` * Bugfix found by #931 (comment) ``` E, [2025-08-26T00:00:44.351193 #2377] ERROR -- rbs: /home/runner/work/gem_rbs_collection/gem_rbs_collection/gems/railties/6.0/_test/.gem_rbs_collection/railties/6.0/railties.rbs:25:32...25:38: Could not find ::Mapper (RBS::NoTypeFoundError) def routes: () ?{ () [self: Mapper] -> void } -> ActionDispatch::Routing::RouteSet ^^^^^^ ``` * 1 method call with untyped receiver detected from test.rb. Please assign the expected type to the receiver * Cleanups * Review response to #932 (review)
1 parent 815e8f9 commit 14112a8

File tree

7 files changed

+39
-111
lines changed

7 files changed

+39
-111
lines changed

gems/actionpack/6.0/actiondispatch.rbs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,23 @@ end
6363

6464
module ActionDispatch
6565
module Routing
66+
module PolymorphicRoutes
67+
def polymorphic_url: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> String
68+
def polymorphic_path: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> String
69+
end
70+
6671
class RouteSet
6772
def draw: () { () [self: Mapper] -> untyped } -> nil
73+
74+
def url_helpers: (?bool supports_path) -> RouteSet_AnonymousModule
75+
76+
class RouteSet_AnonymousModule
77+
include ActiveSupport::Concern
78+
include UrlFor
79+
# https://github.com/rails/rails/blob/v6.0.6.1/actionpack/lib/action_dispatch/routing/route_set.rb#L478
80+
end
6881
end
69-
end
70-
end
7182

72-
module ActionDispatch
73-
module Routing
7483
class Mapper
7584
module HttpHelpers
7685
# Define a route that only recognizes HTTP GET.

gems/actionpack/6.0/actionpack-generated.rbs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9704,54 +9704,6 @@ module ActionDispatch
97049704
# form_for([blog, @post]) # => "/blog/posts/1"
97059705
#
97069706
module PolymorphicRoutes
9707-
# Constructs a call to a named RESTful route for the given record and returns the
9708-
# resulting URL string. For example:
9709-
#
9710-
# # calls post_url(post)
9711-
# polymorphic_url(post) # => "http://example.com/posts/1"
9712-
# polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
9713-
# polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
9714-
# polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
9715-
# polymorphic_url(Comment) # => "http://example.com/comments"
9716-
#
9717-
# ==== Options
9718-
#
9719-
# * <tt>:action</tt> - Specifies the action prefix for the named route:
9720-
# <tt>:new</tt> or <tt>:edit</tt>. Default is no prefix.
9721-
# * <tt>:routing_type</tt> - Allowed values are <tt>:path</tt> or <tt>:url</tt>.
9722-
# Default is <tt>:url</tt>.
9723-
#
9724-
# Also includes all the options from <tt>url_for</tt>. These include such
9725-
# things as <tt>:anchor</tt> or <tt>:trailing_slash</tt>. Example usage
9726-
# is given below:
9727-
#
9728-
# polymorphic_url([blog, post], anchor: 'my_anchor')
9729-
# # => "http://example.com/blogs/1/posts/1#my_anchor"
9730-
# polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app")
9731-
# # => "http://example.com/my_app/blogs/1/posts/1#my_anchor"
9732-
#
9733-
# For all of these options, see the documentation for {url_for}[rdoc-ref:ActionDispatch::Routing::UrlFor].
9734-
#
9735-
# ==== Functionality
9736-
#
9737-
# # an Article record
9738-
# polymorphic_url(record) # same as article_url(record)
9739-
#
9740-
# # a Comment record
9741-
# polymorphic_url(record) # same as comment_url(record)
9742-
#
9743-
# # it recognizes new records and maps to the collection
9744-
# record = Comment.new
9745-
# polymorphic_url(record) # same as comments_url()
9746-
#
9747-
# # the class of a record will also map to the collection
9748-
# polymorphic_url(Comment) # same as comments_url()
9749-
#
9750-
def polymorphic_url: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> untyped
9751-
9752-
# Returns the path component of a URL for the given record.
9753-
def polymorphic_path: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> untyped
9754-
97559707
private
97569708

97579709
def polymorphic_url_for_action: (untyped action, untyped record_or_hash, untyped options) -> untyped
@@ -10078,8 +10030,6 @@ module ActionDispatch
1007810030

1007910031
def define_mounted_helper: (untyped name, ?untyped? script_namer) -> (nil | untyped)
1008010032

10081-
def url_helpers: (?bool supports_path) -> untyped
10082-
1008310033
def empty?: () -> untyped
1008410034

1008510035
def add_route: (untyped mapping, untyped name) -> untyped

gems/actionpack/7.2/actiondispatch.rbs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,23 @@ end
6363

6464
module ActionDispatch
6565
module Routing
66+
module PolymorphicRoutes
67+
def polymorphic_url: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> String
68+
def polymorphic_path: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> String
69+
end
70+
6671
class RouteSet
6772
def draw: () { () [self: Mapper] -> untyped } -> nil
73+
74+
def url_helpers: (?bool supports_path) -> RouteSet_AnonymousModule
75+
76+
class RouteSet_AnonymousModule
77+
include ActiveSupport::Concern
78+
include UrlFor
79+
# https://github.com/rails/rails/blob/v7.2.2.2/actionpack/lib/action_dispatch/routing/route_set.rb#L518
80+
end
6881
end
69-
end
70-
end
7182

72-
module ActionDispatch
73-
module Routing
7483
class Mapper
7584
module HttpHelpers
7685
# Define a route that only recognizes HTTP GET.

gems/actionpack/7.2/actionpack-generated.rbs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9704,54 +9704,6 @@ module ActionDispatch
97049704
# form_for([blog, @post]) # => "/blog/posts/1"
97059705
#
97069706
module PolymorphicRoutes
9707-
# Constructs a call to a named RESTful route for the given record and returns the
9708-
# resulting URL string. For example:
9709-
#
9710-
# # calls post_url(post)
9711-
# polymorphic_url(post) # => "http://example.com/posts/1"
9712-
# polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
9713-
# polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
9714-
# polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
9715-
# polymorphic_url(Comment) # => "http://example.com/comments"
9716-
#
9717-
# ==== Options
9718-
#
9719-
# * <tt>:action</tt> - Specifies the action prefix for the named route:
9720-
# <tt>:new</tt> or <tt>:edit</tt>. Default is no prefix.
9721-
# * <tt>:routing_type</tt> - Allowed values are <tt>:path</tt> or <tt>:url</tt>.
9722-
# Default is <tt>:url</tt>.
9723-
#
9724-
# Also includes all the options from <tt>url_for</tt>. These include such
9725-
# things as <tt>:anchor</tt> or <tt>:trailing_slash</tt>. Example usage
9726-
# is given below:
9727-
#
9728-
# polymorphic_url([blog, post], anchor: 'my_anchor')
9729-
# # => "http://example.com/blogs/1/posts/1#my_anchor"
9730-
# polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app")
9731-
# # => "http://example.com/my_app/blogs/1/posts/1#my_anchor"
9732-
#
9733-
# For all of these options, see the documentation for {url_for}[rdoc-ref:ActionDispatch::Routing::UrlFor].
9734-
#
9735-
# ==== Functionality
9736-
#
9737-
# # an Article record
9738-
# polymorphic_url(record) # same as article_url(record)
9739-
#
9740-
# # a Comment record
9741-
# polymorphic_url(record) # same as comment_url(record)
9742-
#
9743-
# # it recognizes new records and maps to the collection
9744-
# record = Comment.new
9745-
# polymorphic_url(record) # same as comments_url()
9746-
#
9747-
# # the class of a record will also map to the collection
9748-
# polymorphic_url(Comment) # same as comments_url()
9749-
#
9750-
def polymorphic_url: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> untyped
9751-
9752-
# Returns the path component of a URL for the given record.
9753-
def polymorphic_path: (untyped record_or_hash_or_array, ?::Hash[untyped, untyped] options) -> untyped
9754-
97559707
private
97569708

97579709
def polymorphic_url_for_action: (untyped action, untyped record_or_hash, untyped options) -> untyped
@@ -10078,8 +10030,6 @@ module ActionDispatch
1007810030

1007910031
def define_mounted_helper: (untyped name, ?untyped? script_namer) -> (nil | untyped)
1008010032

10081-
def url_helpers: (?bool supports_path) -> untyped
10082-
1008310033
def empty?: () -> untyped
1008410034

1008510035
def add_route: (untyped mapping, untyped name) -> untyped

gems/railties/6.0/_test/test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Rails.application.routes.draw do
2+
resources :test1_models
3+
end
4+
5+
raise <<~HEREDOC unless Rails.application.routes.url_helpers.polymorphic_path(:new_test1_model) == '/test1_models/new'
6+
But it should work, since:
7+
>>> Rails.application.routes.method(:url_helpers).source_location
8+
["/usr/local/bundle/gems/actionpack-6.0.6.1/lib/action_dispatch/routing/route_set.rb", 478]
9+
HEREDOC
10+

gems/railties/6.0/railties-generated.rbs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,8 +4774,6 @@ module Rails
47744774

47754775
attr_accessor self.logger: untyped
47764776

4777-
def self.application: () -> untyped
4778-
47794777
# The Configuration instance used to configure the Rails environment
47804778
def self.configuration: () -> untyped
47814779

gems/railties/6.0/railties.rbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module Rails
2222
class Engine
2323
# Defines the routes for this engine. If a block is given to
2424
# routes, it is appended to the engine.
25-
def routes: () ?{ () [self: Mapper] -> void } -> ActionDispatch::Routing::RouteSet
25+
def routes: () ?{ () [self: ActionDispatch::Routing::Mapper] -> void } -> ActionDispatch::Routing::RouteSet
2626
end
2727
end
2828

@@ -36,6 +36,8 @@ module Rails
3636
end
3737

3838
module Rails
39+
def self.application: () -> Rails::Application
40+
3941
class Railties
4042
extend Initializable::ClassMethods
4143
end

0 commit comments

Comments
 (0)