aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb8
-rw-r--r--actionpack/test/dispatch/routing_test.rb14
2 files changed, 14 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index ddee742021..278cf383ee 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -55,10 +55,8 @@ module ActionDispatch
path = normalize_path(path)
if using_match_shorthand?(path, options)
- options = {
- :to => path[1..-1].sub(%r{/([^/]*)$}, '#\1'),
- :as => path[1..-1].gsub("/", "_")
- }.merge!(options)
+ options[:to] ||= path[1..-1].sub(%r{/([^/]*)$}, '#\1')
+ options[:as] ||= path[1..-1].gsub("/", "_")
end
[ path, options ]
@@ -71,7 +69,7 @@ module ActionDispatch
# match "account/overview"
def using_match_shorthand?(path, options)
- path && options.except(:via, :anchor).empty? && !path.include?(':')
+ path && options.except(:via, :anchor, :to, :as).empty? && path =~ %r{^/[\w\/]+$}
end
def normalize_path(path)
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index e0500af29d..87a46feec7 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -18,10 +18,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
default_url_options :host => "rubyonrails.org"
controller :sessions do
- get 'login' => :new, :as => :login
+ get 'login' => :new
post 'login' => :create
-
- delete 'logout' => :destroy, :as => :logout
+ delete 'logout' => :destroy
end
resource :session do
@@ -35,6 +34,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
match 'account/overview'
match '/account/nested/overview'
+ match 'sign_in' => "sessions#new"
match 'account/modulo/:name', :to => redirect("/%{name}s")
match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" }
@@ -673,6 +673,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
+ def test_convention_with_explicit_end
+ with_test_routes do
+ get '/sign_in'
+ assert_equal 'sessions#new', @response.body
+ assert_equal '/sign_in', sign_in_path
+ end
+ end
+
def test_redirect_with_complete_url
with_test_routes do
get '/account/google'