Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Preserve parameter's metatables #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ local function merge(destination, origin, visited)
end
end

setmetatable(destination, getmetatable(origin))
return destination
end

Expand Down
8 changes: 8 additions & 0 deletions spec/router_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ describe("Router", function()
r:execute("POST", "/s/21", {bar = 'bar', baz = 'baz'}, {baz = 'hey'})
assert.same(dummy.params, {id = '21', bar = 'bar', baz = 'baz'})
end)

it("keeps metatables passed as parameters", function()
local meta = {__index = {addn = function(self,value) return value + self.n end}}
local param = {n = 5}
setmetatable(param, meta)
r:execute("POST", "/s/21", param)
assert.are.equal(dummy.params:addn(3), 5 + 3)
end)
end)
end) -- :execute
end) -- default params
Expand Down