test/router.rb in nephos-server-0.6.4 vs test/router.rb in nephos-server-0.6.5
- old
+ new
@@ -185,11 +185,10 @@
REQ_GET_INDEX_XXX_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/XXX/index"})
REQ_POST_INDEX_XXX_ID = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index/XXX/id"})
REQ_POST_INDEX_XXX_XXX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index/XXX/XXX"})
- # TODO : FIX
def test_routing_matching_simple_with_arguments2
reset_routes!
get url: "/index", controller: "TestController", method: "method1", silent: true
get url: "/index/:id", controller: "TestController", method: "method1", silent: true
post url: "/index/:id/index", controller: "TestController", method: "method2", silent: true
@@ -204,8 +203,54 @@
assert(Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_INDEX))
assert(!Nephos::Router.new.find_route(REQ_GET_INDEX_XXX_INDEX))
assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_ID))
assert(!Nephos::Router.new.find_route(REQ_POST_INDEX_XXX_XXX))
+ end
+
+ def test_routing_extension
+ reset_routes!
+ get url: "/index", controller: "TestController", method: "method1", silent: true
+ get url: "/indexno", controller: "TestController", method: "method1", silent: true, postfix: false
+ ok1 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index"})
+ ok2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index.html"})
+ ok3 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index.json"})
+ ok4 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index.xhr"})
+ ok5 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno"})
+ ko1 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index/html"})
+ ko2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.html"})
+ ko3 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.json"})
+ ko4 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexno.xhr"})
+ assert(Nephos::Router.new.find_route(ok1))
+ assert(Nephos::Router.new.find_route(ok2))
+ assert(Nephos::Router.new.find_route(ok3))
+ assert(Nephos::Router.new.find_route(ok4))
+ assert(Nephos::Router.new.find_route(ok5))
+ assert(!Nephos::Router.new.find_route(ko1))
+ assert(!Nephos::Router.new.find_route(ko2))
+ assert(!Nephos::Router.new.find_route(ko3))
+ assert(!Nephos::Router.new.find_route(ko4))
+ end
+
+ def test_routing_eze_router
+ reset_routes!
+ get url: "/index", controller: "TestController", method: "method1", silent: true
+ get url: "/index", to: "TestController#method1", method: "method1", silent: true
+ assert_equal Nephos::Router::ROUTES[0], Nephos::Router::ROUTES[1]
+ end
+
+ def test_routing_multiple_url
+ reset_routes!
+ get url: ["/index"], controller: "TestController", method: "method1", silent: true
+ get url: "/index", controller: "TestController", method: "method1", silent: true
+ reset_routes!
+ get url: ["/index", "/index"], controller: "TestController", method: "method1"
+ get url: ["/index", "/index"], controller: "TestController", method: "method1"
+ assert_equal Nephos::Router::ROUTES[0], Nephos::Router::ROUTES[1]
+ assert_equal Nephos::Router::ROUTES[1], Nephos::Router::ROUTES[2]
+ assert_equal Nephos::Router::ROUTES[2], Nephos::Router::ROUTES[3]
+ reset_routes!
+ get url: ["/index", "/me", "/other"], controller: "TestController", method: "method1"
+ assert_equal 3, Nephos::Router::ROUTES.size
end
end