Skip to content

Commit

Permalink
Add router multiple params test
Browse files Browse the repository at this point in the history
  • Loading branch information
ostinelli committed Sep 20, 2013
1 parent 5ef8d71 commit 3a2698f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion spec/core/router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ describe("Router", function()
routes.GET("/users", { controller = "users", action = "index" })
routes.GET("/users/:id", { controller = "users", action = "show" })
routes.PUT("/users/:id", { controller = "users", action = "edit" })
routes.DELETE("/users/:user_id/messages/:id", { controller = "messages", action = "destroy" })

router.dispatchers = routes.dispatchers
end)

it("returns the controller, action and params", function()
it("returns the controller, action and params for a single param", function()
ngx = {
var = {
uri = "/users/roberto",
Expand All @@ -38,5 +39,20 @@ describe("Router", function()
assert.are.same("show", action)
assert.are.same({ id = "roberto" }, params)
end)

it("returns the controller, action and params for a multiple params", function()
ngx = {
var = {
uri = "/users/roberto/messages/123",
request_method = "DELETE"
}
}

controller, action, params = router.match(ngx)

assert.are.same("messages_controller", controller)
assert.are.same("destroy", action)
assert.are.same({ user_id = "roberto", id = "123" }, params)
end)
end)
end)

0 comments on commit 3a2698f

Please sign in to comment.