mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
decouple the router object from the request class
This commit is contained in:
parent
6fd8346400
commit
0f5e3a9f6b
3 changed files with 10 additions and 21 deletions
|
@ -20,13 +20,11 @@ module ActionDispatch
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
VERSION = '2.0.0'
|
VERSION = '2.0.0'
|
||||||
|
|
||||||
attr_reader :request_class, :formatter
|
attr_reader :formatter
|
||||||
attr_accessor :routes
|
attr_accessor :routes
|
||||||
|
|
||||||
def initialize(routes, options)
|
def initialize(routes)
|
||||||
@options = options
|
@routes = routes
|
||||||
@request_class = options[:request_class]
|
|
||||||
@routes = routes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def serve(req)
|
def serve(req)
|
||||||
|
|
|
@ -302,8 +302,7 @@ module ActionDispatch
|
||||||
@finalized = false
|
@finalized = false
|
||||||
|
|
||||||
@set = Journey::Routes.new
|
@set = Journey::Routes.new
|
||||||
@router = Journey::Router.new(@set, {
|
@router = Journey::Router.new @set
|
||||||
:request_class => request_class})
|
|
||||||
@formatter = Journey::Formatter.new @set
|
@formatter = Journey::Formatter.new @set
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,18 +12,10 @@ module ActionDispatch
|
||||||
def setup
|
def setup
|
||||||
@app = StubDispatcher.new
|
@app = StubDispatcher.new
|
||||||
@routes = Routes.new
|
@routes = Routes.new
|
||||||
@router = Router.new(@routes, {
|
@router = Router.new(@routes)
|
||||||
:request_class => ActionDispatch::Request
|
|
||||||
})
|
|
||||||
@formatter = Formatter.new(@routes)
|
@formatter = Formatter.new(@routes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_request_class_reader
|
|
||||||
klass = Object.new
|
|
||||||
router = Router.new(routes, :request_class => klass)
|
|
||||||
assert_equal klass, router.request_class
|
|
||||||
end
|
|
||||||
|
|
||||||
class FakeRequestFeeler < Struct.new(:env, :called)
|
class FakeRequestFeeler < Struct.new(:env, :called)
|
||||||
def new env
|
def new env
|
||||||
self.env = env
|
self.env = env
|
||||||
|
@ -41,7 +33,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_dashes
|
def test_dashes
|
||||||
router = Router.new(routes, { :request_class => ActionDispatch::Request })
|
router = Router.new(routes)
|
||||||
|
|
||||||
exp = Router::Strexp.new '/foo-bar-baz', {}, ['/.?']
|
exp = Router::Strexp.new '/foo-bar-baz', {}, ['/.?']
|
||||||
path = Path::Pattern.new exp
|
path = Path::Pattern.new exp
|
||||||
|
@ -57,7 +49,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_unicode
|
def test_unicode
|
||||||
router = Router.new(routes, { :request_class => ActionDispatch::Request })
|
router = Router.new(routes)
|
||||||
|
|
||||||
#match the escaped version of /ほげ
|
#match the escaped version of /ほげ
|
||||||
exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
|
exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
|
||||||
|
@ -75,7 +67,7 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_request_class_and_requirements_success
|
def test_request_class_and_requirements_success
|
||||||
klass = FakeRequestFeeler.new nil
|
klass = FakeRequestFeeler.new nil
|
||||||
router = Router.new(routes, {})
|
router = Router.new(routes)
|
||||||
|
|
||||||
requirements = { :hello => /world/ }
|
requirements = { :hello => /world/ }
|
||||||
|
|
||||||
|
@ -95,7 +87,7 @@ module ActionDispatch
|
||||||
|
|
||||||
def test_request_class_and_requirements_fail
|
def test_request_class_and_requirements_fail
|
||||||
klass = FakeRequestFeeler.new nil
|
klass = FakeRequestFeeler.new nil
|
||||||
router = Router.new(routes, {})
|
router = Router.new(routes)
|
||||||
|
|
||||||
requirements = { :hello => /mom/ }
|
requirements = { :hello => /mom/ }
|
||||||
|
|
||||||
|
@ -124,7 +116,7 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_request_class_overrides_path_info
|
def test_request_class_overrides_path_info
|
||||||
router = Router.new(routes, {:request_class => CustomPathRequest })
|
router = Router.new(routes)
|
||||||
|
|
||||||
exp = Router::Strexp.new '/bar', {}, ['/.?']
|
exp = Router::Strexp.new '/bar', {}, ['/.?']
|
||||||
path = Path::Pattern.new exp
|
path = Path::Pattern.new exp
|
||||||
|
|
Loading…
Reference in a new issue