2010-03-08 15:24:49 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
class TestRoutingMount < ActionDispatch::IntegrationTest
|
|
|
|
Router = ActionDispatch::Routing::RouteSet.new
|
2010-12-09 07:15:25 -05:00
|
|
|
|
|
|
|
class FakeEngine
|
|
|
|
def self.routes
|
|
|
|
Object.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.call(env)
|
|
|
|
[200, {"Content-Type" => "text/html"}, ["OK"]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-03-08 15:24:49 -05:00
|
|
|
Router.draw do
|
2010-03-12 05:50:45 -05:00
|
|
|
SprocketsApp = lambda { |env|
|
|
|
|
[200, {"Content-Type" => "text/html"}, ["#{env["SCRIPT_NAME"]} -- #{env["PATH_INFO"]}"]]
|
|
|
|
}
|
|
|
|
|
2010-03-08 15:24:49 -05:00
|
|
|
mount SprocketsApp, :at => "/sprockets"
|
|
|
|
mount SprocketsApp => "/shorthand"
|
|
|
|
|
2010-12-09 07:15:25 -05:00
|
|
|
mount FakeEngine, :at => "/fakeengine"
|
2012-08-20 11:25:23 -04:00
|
|
|
mount FakeEngine, :at => "/getfake", :via => :get
|
2010-12-09 07:15:25 -05:00
|
|
|
|
2010-03-08 15:24:49 -05:00
|
|
|
scope "/its_a" do
|
|
|
|
mount SprocketsApp, :at => "/sprocket"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def app
|
|
|
|
Router
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_mounting_sets_script_name
|
|
|
|
get "/sprockets/omg"
|
|
|
|
assert_equal "/sprockets -- /omg", response.body
|
|
|
|
end
|
|
|
|
|
2012-05-07 17:53:57 -04:00
|
|
|
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
|
|
|
|
|
2010-03-08 15:24:49 -05:00
|
|
|
def test_mounting_works_with_scope
|
|
|
|
get "/its_a/sprocket/omg"
|
|
|
|
assert_equal "/its_a/sprocket -- /omg", response.body
|
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-03-08 15:24:49 -05:00
|
|
|
def test_mounting_with_shorthand
|
|
|
|
get "/shorthand/omg"
|
|
|
|
assert_equal "/shorthand -- /omg", response.body
|
|
|
|
end
|
2010-12-09 07:15:25 -05:00
|
|
|
|
2012-08-20 11:25:23 -04:00
|
|
|
def test_mounting_works_with_via
|
|
|
|
get "/getfake"
|
|
|
|
assert_equal "OK", response.body
|
|
|
|
|
|
|
|
post "/getfake"
|
|
|
|
assert_response :not_found
|
|
|
|
end
|
|
|
|
|
2010-12-09 07:15:25 -05:00
|
|
|
def test_with_fake_engine_does_not_call_invalid_method
|
|
|
|
get "/fakeengine"
|
|
|
|
assert_equal "OK", response.body
|
|
|
|
end
|
2011-12-19 16:34:54 -05:00
|
|
|
end
|