From 9e0c5b14100da44bad548f123ebe852840c882d2 Mon Sep 17 00:00:00 2001 From: Elliot Foster Date: Sun, 24 Nov 2013 16:02:57 -0800 Subject: [PATCH] findOrCreate does not modify inputs This helps when making spy assertions about what arguments findOrCreate was called with. --- lib/dao-factory.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/dao-factory.js b/lib/dao-factory.js index fa0fca4b6e49..b5e7c53a134e 100644 --- a/lib/dao-factory.js +++ b/lib/dao-factory.js @@ -567,16 +567,21 @@ module.exports = (function() { DAOFactory.prototype.findOrCreate = function (params, defaults) { var self = this; + var where = {}; + for (var attrname in params) { + where[attrname] = params[attrname] + } + return new Utils.CustomEventEmitter(function (emitter) { self.find({ - where: params + where: where }).success(function (instance) { if (instance === null) { for (var attrname in defaults) { - params[attrname] = defaults[attrname] + where[attrname] = defaults[attrname] } - self.create(params) + self.create(where) .success(function (instance) { emitter.emit('success', instance, true) })