Skip to content

Commit

Permalink
Add passing tests for generating URLs with nested SCRIPT_NAMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed May 7, 2012
1 parent ed2feb7 commit 4d0e6db
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions actionpack/test/dispatch/mount_test.rb
Expand Up @@ -37,6 +37,11 @@ def test_mounting_sets_script_name
assert_equal "/sprockets -- /omg", response.body
end

def test_mounting_works_with_nested_script_name
get "/foo/sprockets/omg", {}, 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/sprockets/omg'
assert_equal "/foo/sprockets -- /omg", response.body
end

def test_mounting_works_with_scope
get "/its_a/sprocket/omg"
assert_equal "/its_a/sprocket -- /omg", response.body
Expand Down
15 changes: 12 additions & 3 deletions actionpack/test/dispatch/url_generation_test.rb
Expand Up @@ -3,7 +3,7 @@
module TestUrlGeneration
class WithMountPoint < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw { get "/foo", :to => "my_route_generating#index", :as => :foo }
include Routes.url_helpers

class ::MyRouteGeneratingController < ActionController::Base
include Routes.url_helpers
Expand All @@ -12,7 +12,11 @@ def index
end
end

include Routes.url_helpers
Routes.draw do
get "/foo", :to => "my_route_generating#index", :as => :foo

mount MyRouteGeneratingController.action(:index), at: '/bar'
end

def _routes
Routes
Expand All @@ -30,11 +34,16 @@ def app
assert_equal "/bar/foo", foo_path(:script_name => "/bar")
end

test "the request's SCRIPT_NAME takes precedence over the routes'" do
test "the request's SCRIPT_NAME takes precedence over the route" do
get "/foo", {}, 'SCRIPT_NAME' => "/new", 'action_dispatch.routes' => Routes
assert_equal "/new/foo", response.body
end

test "the request's SCRIPT_NAME wraps the mounted app's" do
get '/new/bar/foo', {}, 'SCRIPT_NAME' => '/new', 'PATH_INFO' => '/bar/foo', 'action_dispatch.routes' => Routes
assert_equal "/new/bar/foo", response.body
end

test "handling http protocol with https set" do
https!
assert_equal "http://www.example.com/foo", foo_url(:protocol => "http")
Expand Down

0 comments on commit 4d0e6db

Please sign in to comment.