Skip to content
Browse files

ActionDispatch: remove trailing slash when root_url is called

  • Loading branch information...
1 parent 7be8809 commit 85f333b2c375fc9f22bfc07a03d18334802c8aad @bogdan committed Sep 22, 2012
View
10 actionpack/lib/action_dispatch/http/url.rb
@@ -31,8 +31,16 @@ def url_for(options = {})
params.reject! {|k,v| v.to_param.nil? }
result = build_host_url(options)
+ result << path
+
+
+ if options[:trailing_slash] && result.last != "/"
+ result << "/"
+ elsif result.last == "/"
+ # if result is '/' this is still working
+ result = result[0..result.size-2]
+ end
- result << (options[:trailing_slash] ? path.sub(/\?|\z/) { "/" + $& } : path)
result << "?#{params.to_query}" unless params.empty?
result << "##{Journey::Router::Utils.escape_fragment(options[:anchor].to_param.to_s)}" if options[:anchor]
result
View
8 actionpack/test/controller/routing_test.rb
@@ -361,7 +361,7 @@ def test_basic_named_route
rs.draw do
root :to => 'content#list', :as => 'home'
end
- assert_equal("http://test.host/", setup_for_named_route.send(:home_url))
+ assert_equal("http://test.host", setup_for_named_route.send(:home_url))
end
def test_named_route_with_option
@@ -443,7 +443,7 @@ def test_named_route_root
root :to => "hello#index"
end
routes = setup_for_named_route
- assert_equal("http://test.host/", routes.send(:root_url))
+ assert_equal("http://test.host", routes.send(:root_url))
assert_equal("/", routes.send(:root_path))
end
@@ -452,7 +452,7 @@ def test_named_route_root_without_hash
root "hello#index"
end
routes = setup_for_named_route
- assert_equal("http://test.host/", routes.send(:root_url))
+ assert_equal("http://test.host", routes.send(:root_url))
assert_equal("/", routes.send(:root_path))
end
@@ -654,7 +654,7 @@ def test_named_root_url_generation_with_controller_and_action
assert_equal '/', url_for(rs, { :controller => 'content', :action => 'index' })
assert_equal '/', url_for(rs, { :controller => 'content' })
- assert_equal("http://test.host/", setup_for_named_route.send(:home_url))
+ assert_equal("http://test.host", setup_for_named_route.send(:home_url))
end
def test_named_route_method
View
2 actionpack/test/controller/url_for_test.rb
@@ -325,7 +325,7 @@ def test_named_routes_with_nil_keys
params = {:action => :index, :controller => :posts, :format => :xml}
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
params[:format] = nil
- assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
+ assert_equal("http://www.basecamphq.com", controller.send(:url_for, params))
end
end
View
2 actionpack/test/dispatch/prefix_generation_test.rb
@@ -238,7 +238,7 @@ def setup
test "[OBJECT] generating application's route includes default_url_options[:script_name]" do
RailsApplication.routes.default_url_options = {:script_name => "/something"}
- assert_equal "/something/", app_object.root_path
+ assert_equal "/something", app_object.root_path
end
test "[OBJECT] generating engine's route with url_for" do
View
6 actionpack/test/dispatch/routing_test.rb
@@ -2657,21 +2657,21 @@ class TestUrlConstraints < ActionDispatch::IntegrationTest
def app; Routes end
test "constraints are copied to defaults when using constraints method" do
- assert_equal 'http://admin.example.com/', admin_root_url
+ assert_equal 'http://admin.example.com', admin_root_url
get 'http://admin.example.com/'
assert_response :success
end
test "constraints are copied to defaults when using scope constraints hash" do
- assert_equal 'https://www.example.com/', secure_root_url
+ assert_equal 'https://www.example.com', secure_root_url
get 'https://www.example.com/'
assert_response :success
end
test "constraints are copied to defaults when using route constraints hash" do
- assert_equal 'http://www.example.com:8080/', alternate_root_url
+ assert_equal 'http://www.example.com:8080', alternate_root_url
get 'http://www.example.com:8080/'
assert_response :success
View
2 actionpack/test/template/url_helper_test.rb
@@ -204,7 +204,7 @@ def test_link_tag_without_host_option
def test_link_tag_with_host_option
hash = hash_for(:host => "www.example.com")
- expected = %q{<a href="http://www.example.com/">Test Link</a>}
+ expected = %q{<a href="http://www.example.com">Test Link</a>}
assert_dom_equal(expected, link_to('Test Link', hash))
end

0 comments on commit 85f333b

Please sign in to comment.
Something went wrong with that request. Please try again.