Fix 'defaults' option for root route

The merging of the 'defaults' option was moved up the stack in e852daa6
This allows us to see where these options originate from the standard
HttpHelpers (get, post, patch, put, delete)

Unfortunately this move didn't incorporate the 'root' method, which has
always allowed the same 'defaults' option before.
上级 f88495d5
......@@ -1923,7 +1923,14 @@ def path_scope(path)
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
......
......@@ -1759,6 +1759,24 @@ def test_default_integer_params
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册