Skip to content

Commit

Permalink
Merge pull request #1447 from dmathieu/empty_route
Browse files Browse the repository at this point in the history
Fix creating an empty route on 1.8. Closes #1210
  • Loading branch information
drogus committed Jun 1, 2011
2 parents 63665f6 + 8a0ffa7 commit 0459374
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion actionpack/lib/action_dispatch/routing/mapper.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1423,7 +1423,9 @@ def path_for_action(action, path) #:nodoc:
end end


def action_path(name, path = nil) #:nodoc: def action_path(name, path = nil) #:nodoc:
path || @scope[:path_names][name.to_sym] || name.to_s # Ruby 1.8 can't transform empty strings to symbols
name = name.to_sym if name.is_a?(String) && !name.empty?
path || @scope[:path_names][name] || name.to_s
end end


def prefix_name_for_action(as, action) #:nodoc: def prefix_name_for_action(as, action) #:nodoc:
Expand Down
6 changes: 6 additions & 0 deletions actionpack/test/controller/integration_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ def self.routes
end end


routes.draw do routes.draw do
match '', :to => 'application_integration_test/test#index', :as => :empty_string

match 'foo', :to => 'application_integration_test/test#index', :as => :foo match 'foo', :to => 'application_integration_test/test#index', :as => :foo
match 'bar', :to => 'application_integration_test/test#index', :as => :bar match 'bar', :to => 'application_integration_test/test#index', :as => :bar
end end
Expand All @@ -501,11 +503,15 @@ def app
end end


test "includes route helpers" do test "includes route helpers" do
assert_equal '/', empty_string_path
assert_equal '/foo', foo_path assert_equal '/foo', foo_path
assert_equal '/bar', bar_path assert_equal '/bar', bar_path
end end


test "route helpers after controller access" do test "route helpers after controller access" do
get '/'
assert_equal '/', empty_string_path

get '/foo' get '/foo'
assert_equal '/foo', foo_path assert_equal '/foo', foo_path


Expand Down

0 comments on commit 0459374

Please sign in to comment.