test/test_router.rb in journey-1.0.0 vs test/test_router.rb in journey-1.0.1
- old
+ new
@@ -1,5 +1,6 @@
+# encoding: UTF-8
require 'helper'
module Journey
class TestRouter < MiniTest::Unit::TestCase
attr_reader :routes
@@ -24,10 +25,14 @@
def hello
self.called = true
'world'
end
+
+ def path_info; env['PATH_INFO']; end
+ def request_method; env['REQUEST_METHOD']; end
+ def ip; env['REMOTE_ADDR']; end
end
def test_dashes
klass = FakeRequestFeeler.new nil
router = Router.new(routes, {})
@@ -43,10 +48,28 @@
called = true
end
assert called
end
+ def test_unicode
+ klass = FakeRequestFeeler.new nil
+ router = Router.new(routes, {})
+
+ #match the escaped version of /ほげ
+ exp = Router::Strexp.new '/%E3%81%BB%E3%81%92', {}, ['/.?']
+ path = Path::Pattern.new exp
+
+ routes.add_route nil, path, {}, {:id => nil}, {}
+
+ env = rails_env 'PATH_INFO' => '/%E3%81%BB%E3%81%92'
+ called = false
+ router.recognize(env) do |r, _, params|
+ called = true
+ end
+ assert called
+ end
+
def test_request_class_and_requirements_success
klass = FakeRequestFeeler.new nil
router = Router.new(routes, {:request_class => klass })
requirements = { :hello => /world/ }
@@ -81,9 +104,33 @@
flunk 'route should not be found'
end
assert klass.called, 'hello should have been called'
assert_equal env.env, klass.env
+ end
+
+ class CustomPathRequest < Router::NullReq
+ def path_info
+ env['custom.path_info']
+ end
+ end
+
+ def test_request_class_overrides_path_info
+ router = Router.new(routes, {:request_class => CustomPathRequest })
+
+ exp = Router::Strexp.new '/bar', {}, ['/.?']
+ path = Path::Pattern.new exp
+
+ routes.add_route nil, path, {}, {}, {}
+
+ env = rails_env 'PATH_INFO' => '/foo', 'custom.path_info' => '/bar'
+
+ recognized = false
+ router.recognize(env) do |r, _, params|
+ recognized = true
+ end
+
+ assert recognized, "route should have been recognized"
end
def test_regexp_first_precedence
add_routes @router, [
Router::Strexp.new("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?']),