aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Arcand <chris@chrisarcand.com>2016-07-21 15:59:05 -0500
committerChris Arcand <chris@chrisarcand.com>2016-07-21 15:59:05 -0500
commit31fbbb7faccba25b2e3b5e10b8fca1468579d629 (patch)
treee04f75d020badc4ba2e210b1b54ef580b8af12a0
parentf88495d519f9bdacd542d61b4e8117eb4f79c173 (diff)
downloadrails-31fbbb7faccba25b2e3b5e10b8fca1468579d629.tar.gz
rails-31fbbb7faccba25b2e3b5e10b8fca1468579d629.tar.bz2
rails-31fbbb7faccba25b2e3b5e10b8fca1468579d629.zip
Fix 'defaults' option for root route
The merging of the 'defaults' option was moved up the stack in e852daa 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.
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb9
-rw-r--r--actionpack/test/dispatch/routing_test.rb18
2 files changed, 26 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 73b4864e45..fd68d4f185 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -1923,7 +1923,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
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index 5298e63fef..2fe40de583 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -1759,6 +1759,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