test/router.rb in nephos-server-0.6.1 vs test/router.rb in nephos-server-0.6.2
- old
+ new
@@ -57,34 +57,45 @@
get url: "/", controller: "TestController", method: "method", silent: true
assert_equal "/", first[:url]
assert_equal "GET", first[:verb]
assert_equal "TestController", first[:controller]
assert_equal "method", first[:method]
- assert_equal /^\/\/*$/, first[:match]
+ assert "/".match(first[:match])
+ assert "//".match(first[:match])
+ assert "///".match(first[:match])
reset_routes!
post url: "/", controller: "TestController", method: "method", silent: true
assert_equal "/", first[:url]
assert_equal "POST", first[:verb]
assert_equal "TestController", first[:controller]
assert_equal "method", first[:method]
- assert_equal /^\/\/*$/, first[:match]
+ assert "/".match(first[:match])
+ assert "//".match(first[:match])
+ assert "///".match(first[:match])
reset_routes!
put url: "/", controller: "TestController", method: "method", silent: true
assert_equal "/", first[:url]
assert_equal "PUT", first[:verb]
assert_equal "TestController", first[:controller]
assert_equal "method", first[:method]
- assert_equal /^\/\/*$/, first[:match]
+ assert "/".match(first[:match])
+ assert "//".match(first[:match])
+ assert "///".match(first[:match])
end
def test_valid_routes_params
reset_routes!
get url: "/:what", controller: "TestController", method: "method", silent: true
assert_equal "/:what", first[:url]
- assert_equal /^\/[^\/]+\/*$/, first[:match]
+ assert !"/".match(first[:match])
+ assert !"//".match(first[:match])
+ assert !"///".match(first[:match])
+ assert "/data".match(first[:match])
+ assert "/111".match(first[:match])
+ assert "/--_--".match(first[:match])
end
def test_valid_resources
reset_routes!
resource "/home" do
@@ -100,31 +111,46 @@
reset_routes!
resource "/home" do
get url: "/:what", controller: "TestController", method: "method", silent: true
end
assert_equal "/home/:what", first[:url]
- assert_equal /^\/home\/[^\/]+\/*$/, first[:match]
+ assert !"/JOME/data".match(first[:match])
+ assert !"/1".match(first[:match])
+ assert !"/home".match(first[:match])
+ assert "/home/data".match(first[:match])
+ assert "/home/1".match(first[:match])
end
def test_valid_resources_params2
reset_routes!
resource "/:id" do
get url: "/show", controller: "TestController", method: "method", silent: true
end
assert_equal "/:id/show", first[:url]
- assert_equal /^\/[^\/]+\/show\/*$/, first[:match]
+ assert !"/".match(first[:match])
+ assert !"/x".match(first[:match])
+ assert !"/xx".match(first[:match])
+ assert !"//1".match(first[:match])
+ assert !"/x/1".match(first[:match])
+ assert !"/1/x".match(first[:match])
+ assert !"/x//1".match(first[:match])
+ assert "/1/show".match(first[:match])
+ assert "/show/show".match(first[:match])
+ assert "/1//show".match(first[:match])
end
+ REQ_GET_INDEX_ROOTx2 = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"//index"})
REQ_GET_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/index"})
REQ_POST_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"POST", "PATH_INFO"=>"/index"})
REQ_PUT_INDEX = Rack::Request.new({"REQUEST_METHOD"=>"PUT", "PATH_INFO"=>"/index"})
REQ_GET_INDEXX = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/indexx"})
REQ_GET_INDE = Rack::Request.new({"REQUEST_METHOD"=>"GET", "PATH_INFO"=>"/inde"})
def test_routing_matching_simple
reset_routes!
get url: "/index", controller: "TestController", method: "method", silent: true
post url: "/index", controller: "TestController", method: "method", silent: true
+ assert(Nephos::Router.new.find_route(REQ_GET_INDEX_ROOTx2))
assert(Nephos::Router.new.find_route(REQ_GET_INDEX))
assert(Nephos::Router.new.find_route(REQ_POST_INDEX))
assert(!Nephos::Router.new.find_route(REQ_PUT_INDEX))
assert(!Nephos::Router.new.find_route(REQ_GET_INDEXX))
assert(!Nephos::Router.new.find_route(REQ_GET_INDE))