From 55eb8d72e6ae3420067f150cbd33448f90bc7c0b Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Wed, 24 Aug 2016 16:19:06 -0400 Subject: [PATCH] Reorder PATCH Vs PUT endpoints * Reorder PATCH Vs PUT endpoints for update* methods * Backport of #2670 --- lib/persisted-model.js | 4 ++-- test/remoting.integration.js | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/persisted-model.js b/lib/persisted-model.js index d3e9a6fe..fe2d7c5d 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -633,7 +633,7 @@ module.exports = function(registry) { }; if (!options.replaceOnPUT) { - upsertOptions.http.push({ verb: 'put', path: '/' }); + upsertOptions.http.unshift({ verb: 'put', path: '/' }); } setRemoting(PersistedModel, 'upsert', upsertOptions); @@ -797,7 +797,7 @@ module.exports = function(registry) { setRemoting(PersistedModel.prototype, 'updateAttributes', updateAttributesOptions); if (!options.replaceOnPUT) { - updateAttributesOptions.http.push({ verb: 'put', path: '/' }); + updateAttributesOptions.http.unshift({ verb: 'put', path: '/' }); } if (options.trackChanges || options.enableRemoteReplication) { diff --git a/test/remoting.integration.js b/test/remoting.integration.js index 59b3ca07..c0c4cd31 100644 --- a/test/remoting.integration.js +++ b/test/remoting.integration.js @@ -207,15 +207,25 @@ describe('With model.settings.replaceOnPUT false', function() { var methods = getFormattedMethodsExcludingRelations(storeClass.methods); var expectedMethods = [ - 'upsert(data:object):storeWithReplaceOnPUTfalse PATCH /stores-updating', + 'create(data:object):storeWithReplaceOnPUTfalse POST /stores-updating', 'upsert(data:object):storeWithReplaceOnPUTfalse PUT /stores-updating', + 'upsert(data:object):storeWithReplaceOnPUTfalse PATCH /stores-updating', 'replaceOrCreate(data:object):storeWithReplaceOnPUTfalse POST /stores-updating/replaceOrCreate', + 'exists(id:any):boolean GET /stores-updating/:id/exists', + 'exists(id:any):boolean HEAD /stores-updating/:id', + 'findById(id:any,filter:object):storeWithReplaceOnPUTfalse GET /stores-updating/:id', 'replaceById(id:any,data:object):storeWithReplaceOnPUTfalse POST /stores-updating/:id/replace', - 'prototype.updateAttributes(data:object):storeWithReplaceOnPUTfalse PATCH /stores-updating/:id', + 'find(filter:object):storeWithReplaceOnPUTfalse GET /stores-updating', + 'findOne(filter:object):storeWithReplaceOnPUTfalse GET /stores-updating/findOne', + 'updateAll(where:object,data:object):object POST /stores-updating/update', + 'deleteById(id:any):object DELETE /stores-updating/:id', + 'count(where:object):number GET /stores-updating/count', 'prototype.updateAttributes(data:object):storeWithReplaceOnPUTfalse PUT /stores-updating/:id', + 'prototype.updateAttributes(data:object):storeWithReplaceOnPUTfalse PATCH /stores-updating/:id', + 'createChangeStream(options:object):ReadableStream POST /stores-updating/change-stream', + 'createChangeStream(options:object):ReadableStream GET /stores-updating/change-stream', ]; - - expect(methods).to.include.members(expectedMethods); + expect(methods).to.eql(expectedMethods); }); });