Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api patch) allow PATCH to set an unset field #861

Merged
merged 1 commit into from
Jan 12, 2016
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Other additions include:
- Admin API
- The PUT method now correctly updates boolean fields (such as `strip_request_path`). [#765](https://github.com/Mashape/kong/pull/765)
- The PUT method now correctly resets a plugin configuration. [#720](https://github.com/Mashape/kong/pull/720)
- PATCH correctly set previously unset fields. [#861](https://github.com/Mashape/kong/pull/861)
- In the responses, the `next` link is not being displayed anymore if there are no more entities to be returned. [#635](https://github.com/Mashape/kong/pull/635)
- Prevent the update of `created_at` fields. [#820](https://github.com/Mashape/kong/pull/820)
- Plugins:
Expand Down
2 changes: 1 addition & 1 deletion kong/dao/cassandra/base_dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function BaseDao:update(t, full, where_t)
end

-- Extract primary key from the entity
local t_primary_key, t_no_primary_key = extract_primary_key(old_entity, self._primary_key, self._clustering_key)
local t_primary_key, t_no_primary_key = extract_primary_key(t, self._primary_key, self._clustering_key)

-- If full, add CQL `null` to the SET part of the query for nil columns
if full then
Expand Down
67 changes: 65 additions & 2 deletions spec/integration/admin_api/apis_routes_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,87 @@ describe("Admin API", function()
end)

describe("PATCH", function()
it_content_types("should update if found", function(content_type)
it_content_types("should update name if found", function(content_type)
return function()
local response, status = http_client.patch(BASE_URL..api.id, {
name = "patch-updated"
}, {["content-type"] = content_type})
assert.equal(200, status)
local body = json.decode(response)
assert.equal("patch-updated", body.name)

local rows, err = dao_factory.apis:find_by_keys {id = api.id}
assert.falsy(err)
assert.equal(1, #rows)
local api = rows[1]
assert.equal("patch-updated", api.name)
end
end)
it_content_types("should update by name", function(content_type)
it_content_types("should update name by its old name", function(content_type)
return function()
local response, status = http_client.patch(BASE_URL..api.name, {
name = "patch-updated"
}, {["content-type"] = content_type})
assert.equal(200, status)
local body = json.decode(response)
assert.equal("patch-updated", body.name)

local rows, err = dao_factory.apis:find_by_keys {id = api.id}
assert.falsy(err)
assert.equal(1, #rows)
local api = rows[1]
assert.equal("patch-updated", api.name)
end
end)
it_content_types("should update request_path", function(content_type)
return function()
local response, status = http_client.patch(BASE_URL..api.id, {
request_path = "/httpbin-updated"
}, {["content-type"] = content_type})
assert.equal(200, status)
local body = json.decode(response)
assert.equal("/httpbin-updated", body.request_path)

local rows, err = dao_factory.apis:find_by_keys {id = api.id}
assert.falsy(err)
assert.equal(1, #rows)
local api = rows[1]
assert.equal("/httpbin-updated", api.request_path)
end
end)
it_content_types("should update strip_request_path if it was not previously set", function(content_type)
return function()
local response, status = http_client.patch(BASE_URL..api.id, {
strip_request_path = true
}, {["content-type"] = content_type})
assert.equal(200, status)
local body = json.decode(response)
assert.True(body.strip_request_path)

local rows, err = dao_factory.apis:find_by_keys {id = api.id}
assert.falsy(err)
assert.equal(1, #rows)
local api = rows[1]
assert.True(api.strip_request_path)
end
end)
it_content_types("should update request_host and request_path at once", function(content_type)
return function()
local response, status = http_client.patch(BASE_URL..api.id, {
request_path = "/httpbin-updated-path",
request_host = "httpbin-updated.org"
}, {["content-type"] = content_type})
assert.equal(200, status)
local body = json.decode(response)
assert.equal("/httpbin-updated-path", body.request_path)
assert.equal("httpbin-updated.org", body.request_host)

local rows, err = dao_factory.apis:find_by_keys {id = api.id}
assert.falsy(err)
assert.equal(1, #rows)
local api = rows[1]
assert.equal("/httpbin-updated-path", api.request_path)
assert.equal("httpbin-updated.org", api.request_host)
end
end)
describe("errors", function()
Expand Down