mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #25913 from chrisarcand/fix-keyed-defaults-with-root
Fix keyed defaults with root
This commit is contained in:
parent
8c9cf5c0b3
commit
ec07105545
3 changed files with 34 additions and 2 deletions
|
@ -1,4 +1,11 @@
|
|||
* Check `request.path_parameters` encoding at the point they're set
|
||||
* Fix 'defaults' option for root route.
|
||||
|
||||
A regression from some refactoring for the 5.0 release, this change
|
||||
fixes the use of 'defaults' (default parameters) in the 'root' routing method.
|
||||
|
||||
*Chris Arcand*
|
||||
|
||||
* Check `request.path_parameters` encoding at the point they're set.
|
||||
|
||||
Check for any non-UTF8 characters in path parameters at the point they're
|
||||
set in `env`. Previously they were checked for when used to get a controller
|
||||
|
|
|
@ -1932,7 +1932,14 @@ to this:
|
|||
|
||||
def match_root_route(options)
|
||||
name = has_named_route?(:root) ? nil : :root
|
||||
match '/', { :as => name, :via => :get }.merge!(options)
|
||||
defaults_option = options.delete(:defaults)
|
||||
args = ['/', { as: name, via: :get }.merge!(options)]
|
||||
|
||||
if defaults_option
|
||||
defaults(defaults_option) { match(*args) }
|
||||
else
|
||||
match(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1788,6 +1788,24 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
|||
assert_equal 1, @request.params[:page]
|
||||
end
|
||||
|
||||
def test_keyed_default_string_params_with_root
|
||||
draw do
|
||||
root to: 'pages#show', defaults: { id: 'home' }
|
||||
end
|
||||
|
||||
get '/'
|
||||
assert_equal 'home', @request.params[:id]
|
||||
end
|
||||
|
||||
def test_default_string_params_with_root
|
||||
draw do
|
||||
root to: 'pages#show', id: 'home'
|
||||
end
|
||||
|
||||
get '/'
|
||||
assert_equal 'home', @request.params[:id]
|
||||
end
|
||||
|
||||
def test_resource_constraints
|
||||
draw do
|
||||
resources :products, :constraints => { :id => /\d{4}/ } do
|
||||
|
|
Loading…
Reference in a new issue