diff --git a/README.md b/README.md index fe4ccf0..de1632e 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,19 @@ ENV.emberPouch.remoteDb = 'http://localhost:5984/my_couch'; EmberPouch supports both `hasMany` and `belongsTo` relationships. -### Saving +### Don't save hasMany child ids + +To be more in line with the normal ember data way of saving `hasMany` - `belongsTo` relationships, ember-pouch now has an option to not save the child ids on the `hasMany` side. This prevents the extra need to save the `hasMany` side as explained below. For a more detailed explanation please read the [relational-pouch documentation](https://github.com/nolanlawson/relational-pouch#dont-save-hasmany) + +This new mode can be selected for a `hasMany` relationship by specifying the option `dontsave: true` on the relationship. An application wide setting named `ENV.emberpouch.dontsavehasmany` can also be set to `true` to make all `hasMany` relationships behave this way. + +Using this mode does impose a slight runtime overhead, since this will use `db.find` and database indexes to search for the child ids. The indexes are created automatically for you. But large changes to the model might require you to clean up old, unused indexes. + +### Saving child ids + +When you do save child ids on the `hasMany` side, you have to follow the directions below to make sure the data is saved correctly + +#### Adding entries When saving a `hasMany` - `belongsTo` relationship, both sides of the relationship (the child and the parent) must be saved. Note that the parent needs to have been saved at least once prior to adding children to it. @@ -163,7 +175,7 @@ export default Ember.Route.extend({ ``` -### Removing +#### Removing child ids When removing a `hasMany` - `belongsTo` relationship, the children must be removed prior to the parent being removed. @@ -498,6 +510,9 @@ This project was originally based on the [ember-data-hal-adapter](https://github And of course thanks to all our wonderful contributors, [here](https://github.com/nolanlawson/ember-pouch/graphs/contributors) and [in Relational Pouch](https://github.com/nolanlawson/relational-pouch/graphs/contributors)! ## Changelog +* **4.1.0** + - async is now true when not specified for relationships + - hasMany relationship can have option dontsave * **4.0.3** - Fixes [#158](https://github.com/nolanlawson/ember-pouch/pull/158) * **4.0.2** diff --git a/addon/adapters/pouch.js b/addon/adapters/pouch.js index d00164e..c3efbeb 100644 --- a/addon/adapters/pouch.js +++ b/addon/adapters/pouch.js @@ -1,5 +1,6 @@ import Ember from 'ember'; import DS from 'ember-data'; +import getOwner from 'ember-getowner-polyfill'; import { extractDeleteRecord @@ -146,10 +147,11 @@ export default DS.RESTAdapter.extend({ if (type.documentType) { schemaDef['documentType'] = type.documentType; } - + + let config = getOwner(this).resolveRegistration('config:environment'); + let dontsavedefault = config['emberpouch'] && config['emberpouch']['dontsavehasmany']; // else it's new, so update this._schema.push(schemaDef); - // check all the subtypes // We check the type of `rel.type`because with ember-data beta 19 // `rel.type` switched from DS.Model to string @@ -161,14 +163,40 @@ export default DS.RESTAdapter.extend({ var relDef = {}, relModel = (typeof rel.type === 'string' ? store.modelFor(rel.type) : rel.type); if (relModel) { - relDef[rel.kind] = { - type: self.getRecordTypeName(relModel), - options: rel.options - }; - if (!schemaDef.relations) { - schemaDef.relations = {}; + let includeRel = true; + rel.options = rel.options || {}; + if (typeof(rel.options.async) === "undefined") { + rel.options.async = config.emberpouch && !Ember.isEmpty(config.emberpouch.async) ? config.emberpouch.async : true;//default true from https://github.com/emberjs/data/pull/3366 + } + let options = Object.create(rel.options); + if (rel.kind === 'hasMany' && (options.dontsave || typeof(options.dontsave) === 'undefined' && dontsavedefault)) { + let inverse = type.inverseFor(rel.key, store); + if (inverse) { + if (inverse.kind === 'belongsTo') { + self.get('db').createIndex({index: { fields: ['data.' + inverse.name, '_id'] }}); + if (options.async) { + includeRel = false; + } else { + options.queryInverse = inverse.name; + } + } else { + console.warn(type.modelName + " has a relationship with name " + rel.key + " that is many to many with type " + rel.type + ". This is not supported"); + } + } else { + console.warn(type.modelName + " has a hasMany relationship with name " + rel.key + " that has no inverse."); + } } - schemaDef.relations[rel.key] = relDef; + + if (includeRel) { + relDef[rel.kind] = { + type: self.getRecordTypeName(relModel), + options: options + }; + if (!schemaDef.relations) { + schemaDef.relations = {}; + } + schemaDef.relations[rel.key] = relDef; + } self._init(store, relModel); } }); @@ -280,7 +308,19 @@ export default DS.RESTAdapter.extend({ this._init(store, type); return this.get('db').rel.find(this.getRecordTypeName(type), ids); }, - + + findHasMany: function(store, record, link, rel) { + let inverse = record.type.inverseFor(rel.key, store); + if (inverse && inverse.kind === 'belongsTo') { + return this.get('db').rel.findHasMany(camelize(rel.type), inverse.name, record.id); + } + else { + console.warn("Can't find " + rel.key); + let result = {}; + result[pluralize(rel.type)] = []; + return result;//data; + } + }, query: function(store, type, query) { this._init(store, type); @@ -296,24 +336,7 @@ export default DS.RESTAdapter.extend({ queryParams.sort = this._buildSort(query.sort); } - return db.find(queryParams).then(function (payload) { - if (typeof payload === 'object' && payload !== null) { - var plural = pluralize(recordTypeName); - var results = {}; - - var rows = payload.docs.map((row) => { - var parsedId = db.rel.parseDocID(row._id); - if (!Ember.isEmpty(parsedId.id)) { - row.data.id = parsedId.id; - return row.data; - } - }); - - results[plural] = rows; - - return results; - } - }); + return db.find(queryParams).then(pouchRes => db.rel.parseRelDocs(recordTypeName, pouchRes.docs)); }, queryRecord: function(store, type, query) { diff --git a/addon/serializers/pouch.js b/addon/serializers/pouch.js index 4043de4..1d6f987 100644 --- a/addon/serializers/pouch.js +++ b/addon/serializers/pouch.js @@ -1,5 +1,6 @@ import Ember from 'ember'; import DS from 'ember-data'; +import getOwner from 'ember-getowner-polyfill'; const { get, @@ -8,20 +9,36 @@ const keys = Object.keys || Ember.keys; const assign = Object.assign || Ember.assign; export default DS.RESTSerializer.extend({ - _shouldSerializeHasMany: function() { - return true; + + init: function() { + this._super(...arguments); + + let config = getOwner(this).resolveRegistration('config:environment'); + this.dontsavedefault = config['emberpouch'] && config['emberpouch']['dontsavehasmany']; + }, + + _getDontsave(relationship) { + return !Ember.isEmpty(relationship.options.dontsave) ? relationship.options.dontsave : this.dontsavedefault; + }, + + _shouldSerializeHasMany: function(snapshot, key, relationship) { + let dontsave = this._getDontsave(relationship); + let result = !dontsave; + return result; }, // This fixes a failure in Ember Data 1.13 where an empty hasMany // was saving as undefined rather than []. serializeHasMany(snapshot, json, relationship) { - this._super.apply(this, arguments); - - const key = relationship.key; - - if (!json[key]) { - json[key] = []; - } + if (this._shouldSerializeHasMany(snapshot, relationship.key, relationship)) { + this._super.apply(this, arguments); + + const key = relationship.key; + + if (!json[key]) { + json[key] = []; + } + } }, _isAttachment(attribute) { @@ -66,5 +83,17 @@ export default DS.RESTSerializer.extend({ } }); return attributes; + }, + + extractRelationships(modelClass) { + let relationships = this._super(...arguments); + + modelClass.eachRelationship((key, relationshipMeta) => { + if (relationshipMeta.kind === 'hasMany' && this._getDontsave(relationshipMeta) && !!relationshipMeta.options.async) { + relationships[key] = { links: { related: key } }; + } + }); + + return relationships; } }); diff --git a/blueprints/ember-pouch/index.js b/blueprints/ember-pouch/index.js index eb7f7a0..718283d 100644 --- a/blueprints/ember-pouch/index.js +++ b/blueprints/ember-pouch/index.js @@ -6,7 +6,7 @@ module.exports = { afterInstall: function() { return this.addBowerPackagesToProject([ { name: 'pouchdb', target: '^5.4.5' }, - { name: 'relational-pouch', target: '^1.4.4'}, + { name: 'relational-pouch', target: '^1.4.5'}, { name: 'pouchdb-find', target: '^0.10.2'} ]); } diff --git a/bower.json b/bower.json index 3c10f78..8419241 100644 --- a/bower.json +++ b/bower.json @@ -4,7 +4,7 @@ "ember": "~2.8.0", "ember-cli-shims": "0.1.1", "pouchdb": "^5.4.5", - "relational-pouch": "^1.4.4", + "relational-pouch": "^1.4.5", "pouchdb-find": "^0.10.3", "phantomjs-polyfill-object-assign": "chuckplantain/phantomjs-polyfill-object-assign" } diff --git a/package.json b/package.json index a312435..ff79cc4 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "ember-data": "^2.8.0", "ember-disable-prototype-extensions": "^1.1.0", "ember-export-application-global": "^1.0.5", + "ember-getowner-polyfill": "1.0.1", "ember-load-initializers": "^0.5.1", "ember-resolver": "^2.0.3", "loader.js": "^4.0.1" diff --git a/tests/dummy/app/adapter.js b/tests/dummy/app/adapter.js new file mode 100644 index 0000000..1971394 --- /dev/null +++ b/tests/dummy/app/adapter.js @@ -0,0 +1,14 @@ +import {Adapter} from 'ember-pouch'; +import config from 'dummy/config/environment'; + +export default Adapter.extend({ + _init(store, type) { + type.eachRelationship((name, rel) => { + rel.options.async = config.emberpouch.async; + if (rel.kind === 'hasMany') { + rel.options.dontsave = config.emberpouch.dontsavehasmany; + } + }); + this._super(...arguments); + }, +}); diff --git a/tests/dummy/app/adapters/application.js b/tests/dummy/app/adapters/application.js index 2ee8495..1825349 100644 --- a/tests/dummy/app/adapters/application.js +++ b/tests/dummy/app/adapters/application.js @@ -1,4 +1,4 @@ -import { Adapter } from 'ember-pouch'; +import Adapter from 'dummy/adapter'; import PouchDB from 'pouchdb'; import config from 'dummy/config/environment'; import Ember from 'ember'; diff --git a/tests/dummy/app/adapters/taco-salad.js b/tests/dummy/app/adapters/taco-salad.js index 58d3cb2..2a2bc0e 100644 --- a/tests/dummy/app/adapters/taco-salad.js +++ b/tests/dummy/app/adapters/taco-salad.js @@ -1,4 +1,4 @@ -import { Adapter } from 'ember-pouch/index'; +import Adapter from 'dummy/adapter'; import PouchDB from 'pouchdb'; import config from 'dummy/config/environment'; import Ember from 'ember'; diff --git a/tests/dummy/app/models/food-item.js b/tests/dummy/app/models/food-item.js index 702c0d3..820eab9 100644 --- a/tests/dummy/app/models/food-item.js +++ b/tests/dummy/app/models/food-item.js @@ -1,10 +1,9 @@ import DS from 'ember-data'; +import {Model} from 'ember-pouch'; // N.b.: awkward model name is to test getRecordTypeName -export default DS.Model.extend({ - rev: DS.attr('string'), - +export default Model.extend({ name: DS.attr('string'), - soup: DS.belongsTo('taco-soup', { async: true }) + soup: DS.belongsTo('taco-soup') }); diff --git a/tests/dummy/app/models/smasher.js b/tests/dummy/app/models/smasher.js index b8eca69..22e0d61 100644 --- a/tests/dummy/app/models/smasher.js +++ b/tests/dummy/app/models/smasher.js @@ -1,8 +1,7 @@ import DS from 'ember-data'; +import {Model} from 'ember-pouch'; -export default DS.Model.extend({ - rev: DS.attr('string'), - +export default Model.extend({ name: DS.attr('string'), series: DS.attr('string'), debut: DS.attr(), diff --git a/tests/dummy/app/models/taco-recipe.js b/tests/dummy/app/models/taco-recipe.js index 67677e2..1ee97b8 100644 --- a/tests/dummy/app/models/taco-recipe.js +++ b/tests/dummy/app/models/taco-recipe.js @@ -1,8 +1,7 @@ import DS from 'ember-data'; +import {Model} from 'ember-pouch'; -export default DS.Model.extend({ - rev: DS.attr('string'), - +export default Model.extend({ coverImage: DS.attr('attachment'), photos: DS.attr('attachments') }); diff --git a/tests/dummy/app/models/taco-salad.js b/tests/dummy/app/models/taco-salad.js index 8cc83c4..0d8d252 100644 --- a/tests/dummy/app/models/taco-salad.js +++ b/tests/dummy/app/models/taco-salad.js @@ -1,8 +1,7 @@ import DS from 'ember-data'; +import {Model} from 'ember-pouch'; -export default DS.Model.extend({ - rev: DS.attr('string'), - +export default Model.extend({ flavor: DS.attr('string'), - ingredients: DS.hasMany('food-item', { async: true }) + ingredients: DS.hasMany('food-item') }); diff --git a/tests/dummy/app/models/taco-soup.js b/tests/dummy/app/models/taco-soup.js index 8cc83c4..0d8d252 100644 --- a/tests/dummy/app/models/taco-soup.js +++ b/tests/dummy/app/models/taco-soup.js @@ -1,8 +1,7 @@ import DS from 'ember-data'; +import {Model} from 'ember-pouch'; -export default DS.Model.extend({ - rev: DS.attr('string'), - +export default Model.extend({ flavor: DS.attr('string'), - ingredients: DS.hasMany('food-item', { async: true }) + ingredients: DS.hasMany('food-item') }); diff --git a/tests/helpers/module-for-pouch-acceptance.js b/tests/helpers/module-for-pouch-acceptance.js index 65c61ba..72c8268 100644 --- a/tests/helpers/module-for-pouch-acceptance.js +++ b/tests/helpers/module-for-pouch-acceptance.js @@ -6,15 +6,23 @@ import config from 'dummy/config/environment'; import Ember from 'ember'; /* globals PouchDB */ -export default function(name, options = {}) { +export default function(name, options = {}, nested = undefined) { module(name, { beforeEach(assert) { var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { - return (new PouchDB(config.emberpouch.localDb)).destroy(); + + let db = new PouchDB(config.emberpouch.localDb); + + return db.getIndexes().then(data => { + return Ember.RSVP.all(data.indexes.map( + index => { + return index.ddoc ? (db.deleteIndex(index)) : (Ember.RSVP.resolve()); + })); + }).then(() => db.destroy()); }).then(() => { - this.application = startApp(); + this.application = startApp(); this.lookup = function (item) { return this.application.__container__.lookup(item); @@ -38,15 +46,18 @@ export default function(name, options = {}) { if (options.beforeEach) { options.beforeEach.apply(this, arguments); } - }).finally(done); + done(); + }); }, afterEach() { - destroyApp(this.application); + if (this.application) { + destroyApp(this.application); + } if (options.afterEach) { options.afterEach.apply(this, arguments); } } - }); + }, nested); } diff --git a/tests/integration/adapters/pouch-basics-test.js b/tests/integration/adapters/pouch-basics-test.js index 6c6b960..3230032 100644 --- a/tests/integration/adapters/pouch-basics-test.js +++ b/tests/integration/adapters/pouch-basics-test.js @@ -1,15 +1,21 @@ -import { test } from 'qunit'; +import { module, test } from 'qunit'; + import DS from 'ember-data'; import moduleForIntegration from '../../helpers/module-for-pouch-acceptance'; import Ember from 'ember'; +import config from 'dummy/config/environment'; + /* * Tests basic CRUD behavior for an app using the ember-pouch adapter. */ -moduleForIntegration('Integration | Adapter | Basic CRUD Ops'); + +moduleForIntegration('Integration | Adapter | Basic CRUD Ops', {}, function() { +let allTests = function() { + test('can find all', function (assert) { assert.expect(3); @@ -28,12 +34,7 @@ test('can find all', function (assert) { 'should have extracted the IDs correctly'); assert.deepEqual(found.mapBy('flavor'), ['al pastor', 'black bean'], 'should have extracted the attributes also'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('can find one', function (assert) { @@ -52,15 +53,11 @@ test('can find one', function (assert) { 'should have found the requested item'); assert.deepEqual(found.get('flavor'), 'black bean', 'should have extracted the attributes also'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('can query with sort', function (assert) { + assert.expect(3); var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { return this.db().createIndex({ index: { @@ -85,15 +82,11 @@ test('can query with sort', function (assert) { 'should have extracted the IDs correctly'); assert.deepEqual(found.mapBy('name'), ['Donkey Kong', 'Jigglypuff', 'Link', 'Mario','Pikachu'], 'should have extracted the attributes also'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('can query multi-field queries', function (assert) { + assert.expect(3); var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { return this.db().createIndex({ index: { @@ -120,27 +113,40 @@ test('can query multi-field queries', function (assert) { 'should have extracted the IDs correctly'); assert.deepEqual(found.mapBy('name'), ['Mario', 'Donkey Kong'], 'should have extracted the attributes also'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); +function savingHasMany() { + return !config.emberpouch.dontsavehasmany; +} + +function getDocsForRelations() { + let result = []; + + let c = { _id: 'tacoSoup_2_C', data: { flavor: 'al pastor' } }; + if (savingHasMany()) { c.data.ingredients = ['X', 'Y']; } + result.push(c); + + let d = { _id: 'tacoSoup_2_D', data: { flavor: 'black bean' } }; + if (savingHasMany()) { d.data.ingredients = ['Z']; } + result.push(d); + + result.push({ _id: 'foodItem_2_X', data: { name: 'pineapple', soup: 'C' }}); + result.push({ _id: 'foodItem_2_Y', data: { name: 'pork loin', soup: 'C' }}); + result.push({ _id: 'foodItem_2_Z', data: { name: 'black beans', soup: 'D' }}); + + return result; +} + test('can query one record', function (assert) { + assert.expect(1); + var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { return this.db().createIndex({ index: { fields: ['data.flavor'] } }).then(() => { - return this.db().bulkDocs([ - { _id: 'tacoSoup_2_C', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } }, - { _id: 'tacoSoup_2_D', data: { flavor: 'black bean', ingredients: ['Z'] } }, - { _id: 'foodItem_2_X', data: { name: 'pineapple' }}, - { _id: 'foodItem_2_Y', data: { name: 'pork loin' }}, - { _id: 'foodItem_2_Z', data: { name: 'black beans' }} - ]); + return this.db().bulkDocs(getDocsForRelations()); }); }).then(() => { return this.store().queryRecord('taco-soup', { @@ -149,27 +155,17 @@ test('can query one record', function (assert) { }).then((found) => { assert.equal(found.get('flavor'), 'al pastor', 'should have found the requested item'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('can query one associated records', function (assert) { + assert.expect(3); var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { return this.db().createIndex({ index: { fields: ['data.flavor'] } }).then(() => { - return this.db().bulkDocs([ - { _id: 'tacoSoup_2_C', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } }, - { _id: 'tacoSoup_2_D', data: { flavor: 'black bean', ingredients: ['Z'] } }, - { _id: 'foodItem_2_X', data: { name: 'pineapple' }}, - { _id: 'foodItem_2_Y', data: { name: 'pork loin' }}, - { _id: 'foodItem_2_Z', data: { name: 'black beans' }} - ]); + return this.db().bulkDocs(getDocsForRelations()); }); }).then(() => { return this.store().queryRecord('taco-soup', { @@ -183,12 +179,7 @@ test('can query one associated records', function (assert) { 'should have found both associated items'); assert.deepEqual(foundIngredients.mapBy('name'), ['pineapple', 'pork loin'], 'should have fully loaded the associated items'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('can find associated records', function (assert) { @@ -196,13 +187,7 @@ test('can find associated records', function (assert) { var done = assert.async(); Ember.RSVP.Promise.resolve().then(() => { - return this.db().bulkDocs([ - { _id: 'tacoSoup_2_C', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } }, - { _id: 'tacoSoup_2_D', data: { flavor: 'black bean', ingredients: ['Z'] } }, - { _id: 'foodItem_2_X', data: { name: 'pineapple' }}, - { _id: 'foodItem_2_Y', data: { name: 'pork loin' }}, - { _id: 'foodItem_2_Z', data: { name: 'black beans' }} - ]); + return this.db().bulkDocs(getDocsForRelations()); }).then(() => { return this.store().find('taco-soup', 'C'); }).then((found) => { @@ -214,12 +199,7 @@ test('can find associated records', function (assert) { 'should have found both associated items'); assert.deepEqual(foundIngredients.mapBy('name'), ['pineapple', 'pork loin'], 'should have fully loaded the associated items'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('create a new record', function (assert) { @@ -238,12 +218,7 @@ test('create a new record', function (assert) { assert.equal(newDoc._rev, recordInStore.get('rev'), 'should have associated the ember-data record with the rev for the new record'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); test('creating an associated record stores a reference to it in the parent', function (assert) { @@ -264,16 +239,15 @@ test('creating an associated record stores a reference to it in the parent', fun return newIngredient.save().then(() => tacoSoup.save()); }).then(() => { - this.store().unloadAll(); - + this.store().unloadAll(); + return this.store().findRecord('taco-soup', 'C'); }).then(tacoSoup => { return tacoSoup.get('ingredients'); }).then(foundIngredients => { assert.deepEqual(foundIngredients.mapBy('name'), ['pineapple'], 'should have fully loaded the associated items'); - done(); - }); + }).finally(done); }); // This test fails due to a bug in ember data @@ -303,12 +277,7 @@ if (!DS.VERSION.match(/^2\.0/)) { assert.equal(updatedDoc._rev, recordInStore.get('rev'), 'should have associated the ember-data record with the updated rev'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); }); } @@ -331,10 +300,33 @@ test('delete an existing record', function (assert) { assert.ok(!doc, 'document should no longer exist'); }, (result) => { assert.equal(result.status, 404, 'document should no longer exist'); - done(); - }).catch((error) => { - console.error('error in test', error); - assert.ok(false, 'error in test:' + error); - done(); - }); + }).finally(done); +}); + +}; + + let syncAsync = function() { + module('async', { + beforeEach: function() { + config.emberpouch.async = true; + } + }, allTests); + module('sync', { + beforeEach: function() { + config.emberpouch.async = false; + } + }, allTests); + }; + + module('dont save hasMany', { + beforeEach: function() { + config.emberpouch.dontsavehasmany = true; + } + }, syncAsync); + + module('save hasMany', { + beforeEach: function() { + config.emberpouch.dontsavehasmany = false; + } + }, syncAsync); }); diff --git a/tests/integration/adapters/pouch-default-change-watcher-test.js b/tests/integration/adapters/pouch-default-change-watcher-test.js index 64e2bb3..0429c5c 100644 --- a/tests/integration/adapters/pouch-default-change-watcher-test.js +++ b/tests/integration/adapters/pouch-default-change-watcher-test.js @@ -15,9 +15,9 @@ moduleForIntegration('Integration | Adapter | Default Change Watcher', { return this.db().bulkDocs([ { _id: 'tacoSoup_2_A', data: { flavor: 'al pastor', ingredients: ['X', 'Y'] } }, { _id: 'tacoSoup_2_B', data: { flavor: 'black bean', ingredients: ['Z'] } }, - { _id: 'foodItem_2_X', data: { name: 'pineapple' } }, - { _id: 'foodItem_2_Y', data: { name: 'pork loin' } }, - { _id: 'foodItem_2_Z', data: { name: 'black beans' } } + { _id: 'foodItem_2_X', data: { name: 'pineapple', soup: 'A' } }, + { _id: 'foodItem_2_Y', data: { name: 'pork loin', soup: 'A' } }, + { _id: 'foodItem_2_Z', data: { name: 'black beans', soup: 'B' } } ]); }).finally(done); } @@ -51,7 +51,7 @@ test('a loaded instance automatically reflects directly-made database changes', var alreadyLoadedSoupB = this.store().peekRecord('taco-soup', 'B'); assert.equal(alreadyLoadedSoupB.get('flavor'), 'carnitas', 'the loaded instance should automatically reflect the change in the database'); - }, 15); + }, 100); }).finally(done); }); @@ -111,7 +111,7 @@ test('a deleted record is automatically unloaded', function (assert) { return promiseToRunLater(() => { assert.equal(null, this.store().peekRecord('taco-soup', 'B'), 'the corresponding instance should no longer be loaded'); - }, 15); + }, 100); }).finally(done); });