From a6fc9badfe5da4cf2878ca635e0b5387d2e325ef Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 3 Dec 2014 08:59:40 -0800 Subject: [PATCH] [Persistence] Hide dangling underscores Hide dangling underscores; JSLint considers these a problem and the command line build fails as a consequence when they are present directly in the code, but CouchDB provides these so we cannot avoid them entirely. So, hide them behind variables and use []-style lookup. Concludes transition work for the CouchDB persistence adapter, WTD-537. --- .../src/CouchPersistenceProvider.js | 8 ++++++-- .../persistence/test/CouchDocumentSpec.js | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/platform/persistence/src/CouchPersistenceProvider.js b/platform/persistence/src/CouchPersistenceProvider.js index 1b5ae38a79..3502706257 100644 --- a/platform/persistence/src/CouchPersistenceProvider.js +++ b/platform/persistence/src/CouchPersistenceProvider.js @@ -5,6 +5,11 @@ define( function (CouchDocument) { 'use strict'; + // JSLint doesn't like dangling _'s, but CouchDB uses these, so + // hide this behind variables. + var REV = "_rev", + ID = "_id"; + /** * The CouchPersistenceProvider reads and writes JSON documents * (more specifically, domain object models) to/from a CouchDB @@ -50,10 +55,9 @@ define( } // Get a domain object model out of CouchDB's response - /*jslint nomen: true */ // Allow the _id and _rev that couch provides function getModel(response) { if (response && response.model) { - revs[response._id] = response._rev; + revs[response[ID]] = response[REV]; return response.model; } else { return undefined; diff --git a/platform/persistence/test/CouchDocumentSpec.js b/platform/persistence/test/CouchDocumentSpec.js index aeb6788c8f..e6969e132b 100644 --- a/platform/persistence/test/CouchDocumentSpec.js +++ b/platform/persistence/test/CouchDocumentSpec.js @@ -8,19 +8,22 @@ define( function (CouchDocument) { "use strict"; - // Don't complain about _id or _rev; these are the CouchDB - // fields that must be used. - /*jslint nomen: true */ + // JSLint doesn't like dangling _'s, but CouchDB uses these, so + // hide this behind variables. + var REV = "_rev", + ID = "_id", + DELETED = "_deleted"; + describe("A couch document", function () { it("includes an id", function () { - expect(new CouchDocument("testId", {})._id) + expect(new CouchDocument("testId", {})[ID]) .toEqual("testId"); }); it("includes a rev only when one is provided", function () { - expect(new CouchDocument("testId", {})._rev) + expect(new CouchDocument("testId", {})[REV]) .not.toBeDefined(); - expect(new CouchDocument("testId", {}, "testRev")._rev) + expect(new CouchDocument("testId", {}, "testRev")[REV]) .toEqual("testRev"); }); @@ -31,9 +34,9 @@ define( }); it("marks documents as deleted only on request", function () { - expect(new CouchDocument("testId", {}, "testRev")._deleted) + expect(new CouchDocument("testId", {}, "testRev")[DELETED]) .not.toBeDefined(); - expect(new CouchDocument("testId", {}, "testRev", true)._deleted) + expect(new CouchDocument("testId", {}, "testRev", true)[DELETED]) .toBe(true); }); });