Skip to content

Commit

Permalink
Added "PATCH" route creation, cuz it should be there.
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewest committed Jan 24, 2015
1 parent 13f31ee commit 8a5da38
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facade",
"version": "0.4.5",
"version": "0.4.6",
"authors": [
"Blake West <[email protected]>"
],
Expand Down
19 changes: 18 additions & 1 deletion dist/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.
});
}

function createPatchRoute(opts) {
var headers = {};
Facade.backend.whenPATCH(opts.resource.url + '/' + opts.item.id)
.respond(function(method, url, data, headers) {
data = data || {};
var route = Facade.findRoute(method, url);
var response = route.getSpecialResponseOr(function() {
var item = getOneItem(opts.resource, opts.item.id);
// Perform the patch on the db object
_.assign(item, JSON.parse(data));
return [200, JSON.stringify(item), headers, 'OK']
})

return response;
});
}


function createDeleteRoute(opts) {
var headers = {};
Expand Down Expand Up @@ -278,6 +295,7 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.
return [
{createWith: createItemIdRoute, method: 'GET'},
{createWith: createPutRoute, method: 'PUT'},
{createWith: createPatchRoute, method: 'PATCH'},
{createWith: createDeleteRoute, method: 'DELETE'}
];
}
Expand Down Expand Up @@ -325,7 +343,6 @@ var Y=s();typeof define=="function"&&typeof define.amd=="object"&&define.amd?(G.

function createExpectationFor(opts) {
var fullUrl = opts.resource.url + opts.route;
console.log('creating expecation');
Facade.backend.expect(opts.method, fullUrl, withJSON(opts.expected))
.respond(function(method, url, requestData, headers) {
requestData = JSON.parse(requestData || "{}");
Expand Down
4 changes: 2 additions & 2 deletions dist/facade.min.js

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@
});
}

function createPatchRoute(opts) {
var headers = {};
Facade.backend.whenPATCH(opts.resource.url + '/' + opts.item.id)
.respond(function(method, url, data, headers) {
data = data || {};
var route = Facade.findRoute(method, url);
var response = route.getSpecialResponseOr(function() {
var item = getOneItem(opts.resource, opts.item.id);
// Perform the patch on the db object
_.assign(item, JSON.parse(data));
return [200, JSON.stringify(item), headers, 'OK']
})

return response;
});
}


function createDeleteRoute(opts) {
var headers = {};
Expand Down Expand Up @@ -222,6 +239,7 @@
return [
{createWith: createItemIdRoute, method: 'GET'},
{createWith: createPutRoute, method: 'PUT'},
{createWith: createPatchRoute, method: 'PATCH'},
{createWith: createDeleteRoute, method: 'DELETE'}
];
}
Expand Down Expand Up @@ -269,7 +287,6 @@

function createExpectationFor(opts) {
var fullUrl = opts.resource.url + opts.route;
console.log('creating expecation');
Facade.backend.expect(opts.method, fullUrl, withJSON(opts.expected))
.respond(function(method, url, requestData, headers) {
requestData = JSON.parse(requestData || "{}");
Expand Down

0 comments on commit 8a5da38

Please sign in to comment.