From 58dbc638e9a751f06b8af9a93aeb2edbcabb32da Mon Sep 17 00:00:00 2001 From: bmac Date: Tue, 30 Jun 2015 20:49:56 -0400 Subject: [PATCH] Update the defaults for shouldReloadRecord, shouldBackgroundReloadRecord and shouldReloadAll for Ember Data 2.0 --- packages/ember-data/lib/system/adapter.js | 7 +- .../tests/integration/adapter/find-test.js | 12 --- .../adapter/record-persistence-test.js | 19 ++-- .../integration/adapter/rest-adapter-test.js | 89 ++++++++++++------- .../integration/adapter/store-adapter-test.js | 19 ++-- .../tests/integration/debug-adapter-test.js | 6 +- .../tests/integration/filter-test.js | 27 ++++-- .../tests/integration/multiple_stores_test.js | 10 ++- .../tests/integration/records/reload-test.js | 3 + .../tests/integration/records/unload-test.js | 11 ++- .../relationships/belongs-to-test.js | 11 ++- .../relationships/has-many-test.js | 39 +++++++- .../tests/integration/store-test.js | 32 +++++-- .../integration/store/query-record-test.js | 4 +- packages/ember-data/tests/unit/model-test.js | 33 +++++-- .../model/relationships/belongs-to-test.js | 17 ++-- .../unit/model/relationships/has-many-test.js | 5 ++ .../model/relationships/record-array-test.js | 1 + .../tests/unit/record-array-test.js | 8 +- .../tests/unit/store/adapter-interop-test.js | 15 +++- .../ember-data/tests/unit/store/push-test.js | 3 + 21 files changed, 259 insertions(+), 112 deletions(-) diff --git a/packages/ember-data/lib/system/adapter.js b/packages/ember-data/lib/system/adapter.js index ee66cdd9806..77bfc2e21ca 100644 --- a/packages/ember-data/lib/system/adapter.js +++ b/packages/ember-data/lib/system/adapter.js @@ -482,9 +482,7 @@ var Adapter = Ember.Object.extend({ @return {Boolean} */ shouldReloadAll: function(store, snapshotRecordArray) { - var modelName = snapshotRecordArray.type.modelName; - Ember.deprecate(`The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "${modelName}" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.`); - return true; + return !snapshotRecordArray.length; }, /** @@ -504,8 +502,7 @@ var Adapter = Ember.Object.extend({ @return {Boolean} */ shouldBackgroundReloadRecord: function(store, snapshot) { - Ember.deprecate('The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false.'); - return false; + return true; }, /** diff --git a/packages/ember-data/tests/integration/adapter/find-test.js b/packages/ember-data/tests/integration/adapter/find-test.js index dd22aa9b330..7774125a85c 100644 --- a/packages/ember-data/tests/integration/adapter/find-test.js +++ b/packages/ember-data/tests/integration/adapter/find-test.js @@ -31,18 +31,6 @@ test("It raises an assertion when `undefined` is passed as id (#1705)", function }, "You cannot pass `null` as id to the store's find method"); }); -test("store.findAll should trigger a deprecation warning about store.shouldReloadAll", function() { - env.adapter.findAll = function() { - return Ember.RSVP.resolve([]); - }; - - run(function() { - expectDeprecation(function() { - store.findAll('person'); - }, 'The default behavior of shouldReloadAll will change in Ember Data 2.0 to always return false when there is at least one "person" record in the store. If you would like to preserve the current behavior please override shouldReloadAll in your adapter:application and return true.'); - }); -}); - test("When a single record is requested, the adapter's find method should be called unless it's loaded.", function() { expect(2); diff --git a/packages/ember-data/tests/integration/adapter/record-persistence-test.js b/packages/ember-data/tests/integration/adapter/record-persistence-test.js index 1d73cb06dd4..96f263399b9 100644 --- a/packages/ember-data/tests/integration/adapter/record-persistence-test.js +++ b/packages/ember-data/tests/integration/adapter/record-persistence-test.js @@ -25,7 +25,12 @@ module("integration/adapter/record_persistence - Persisting Records", { }); Person.toString = function() { return "Person"; }; - env = setupStore({ person: Person }); + env = setupStore({ + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }), + person: Person + }); store = env.store; }, @@ -58,11 +63,13 @@ test("When a store is committed, the adapter's `commit` method should be called var tom; - env.store.find('person', 1).then(async(function(person) { - tom = person; - set(tom, "name", "Tom Dale"); - tom.save(); - })); + run(function() { + env.store.findRecord('person', 1).then(async(function(person) { + tom = person; + set(tom, "name", "Tom Dale"); + tom.save(); + })); + }); }); test("When a store is committed, the adapter's `commit` method should be called with records that have been created.", function() { diff --git a/packages/ember-data/tests/integration/adapter/rest-adapter-test.js b/packages/ember-data/tests/integration/adapter/rest-adapter-test.js index 01064e2ca33..513ec41a72f 100644 --- a/packages/ember-data/tests/integration/adapter/rest-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/rest-adapter-test.js @@ -576,25 +576,27 @@ test("update - an empty payload is a basic success", function() { }); }); - store.find('post', 1).then(async(function(post) { + run(function() { + var post = store.peekRecord('post', 1); ajaxResponse(); post.set('name', "The Parley Letter"); - return post.save(); - })).then(async(function(post) { - equal(passedUrl, "/posts/1"); - equal(passedVerb, "PUT"); - deepEqual(passedHash.data, { post: { name: "The Parley Letter" } }); + post.save().then(async(function(post) { + equal(passedUrl, "/posts/1"); + equal(passedVerb, "PUT"); + deepEqual(passedHash.data, { post: { name: "The Parley Letter" } }); - equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); - equal(post.get('name'), "The Parley Letter", "the post was updated"); - })); + equal(post.get('hasDirtyAttributes'), false, "the post isn't dirty anymore"); + equal(post.get('name'), "The Parley Letter", "the post was updated"); + })); + }); }); test("update - passes the requestType to buildURL", function() { adapter.buildURL = function(type, id, snapshot, requestType) { return "/posts/" + id + "/" + requestType; }; + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -608,17 +610,20 @@ test("update - passes the requestType to buildURL", function() { }); }); - store.find('post', 1).then(async(function(post) { - ajaxResponse(); + run(function() { + store.findRecord('post', 1).then(async(function(post) { + ajaxResponse(); - post.set('name', "The Parley Letter"); - return post.save(); - })).then(async(function(post) { - equal(passedUrl, "/posts/1/updateRecord"); - })); + post.set('name', "The Parley Letter"); + return post.save(); + })).then(async(function(post) { + equal(passedUrl, "/posts/1/updateRecord"); + })); + }); }); test("update - a payload with updates applies the updates", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -631,7 +636,7 @@ test("update - a payload with updates applies the updates", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ posts: [{ id: 1, name: "Dat Parley Letter" }] }); post.set('name', "The Parley Letter"); @@ -647,6 +652,7 @@ test("update - a payload with updates applies the updates", function() { }); test("update - a payload with updates applies the updates (with legacy singular name)", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -659,7 +665,7 @@ test("update - a payload with updates applies the updates (with legacy singular }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ post: { id: 1, name: "Dat Parley Letter" } }); post.set('name', "The Parley Letter"); @@ -698,6 +704,7 @@ test("update - a payload with sideloaded updates pushes the updates", function() }); test("update - a payload with sideloaded updates pushes the updates", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -710,7 +717,7 @@ test("update - a payload with sideloaded updates pushes the updates", function() }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ posts: [{ id: 1, name: "Dat Parley Letter" }], comments: [{ id: 1, name: "FIRST" }] @@ -732,6 +739,7 @@ test("update - a payload with sideloaded updates pushes the updates", function() }); test("update - a serializer's primary key and attributes are consulted when building the payload", function() { + adapter.shouldBackgroundReloadRecord = () => false; env.registry.register('serializer:post', DS.RESTSerializer.extend({ primaryKey: '_id_', @@ -751,7 +759,7 @@ test("update - a serializer's primary key and attributes are consulted when buil }); ajaxResponse(); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { post.set('name', "The Parley Letter"); return post.save(); })).then(async(function(post) { @@ -762,6 +770,7 @@ test("update - a serializer's primary key and attributes are consulted when buil test("update - hasMany relationships faithfully reflect simultaneous adds and removes", function() { Post.reopen({ comments: DS.hasMany('comment', { async: false }) }); Comment.reopen({ post: DS.belongsTo('post', { async: false }) }); + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -799,8 +808,8 @@ test("update - hasMany relationships faithfully reflect simultaneous adds and re posts: { id: 1, name: "Not everyone uses Rails", comments: [2] } }); - store.find('comment', 2).then(async(function() { - return store.find('post', 1); + store.findRecord('comment', 2).then(async(function() { + return store.findRecord('post', 1); })).then(async(function(post) { var newComment = store.peekRecord('comment', 2); var comments = post.get('comments'); @@ -817,6 +826,7 @@ test("update - hasMany relationships faithfully reflect simultaneous adds and re }); test("delete - an empty payload is a basic success", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -829,7 +839,7 @@ test("delete - an empty payload is a basic success", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse(); post.deleteRecord(); @@ -845,6 +855,7 @@ test("delete - an empty payload is a basic success", function() { }); test("delete - passes the requestType to buildURL", function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.buildURL = function(type, id, snapshot, requestType) { return "/posts/" + id + "/" + requestType; }; @@ -861,7 +872,7 @@ test("delete - passes the requestType to buildURL", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse(); post.deleteRecord(); @@ -872,6 +883,7 @@ test("delete - passes the requestType to buildURL", function() { }); test("delete - a payload with sideloaded updates pushes the updates", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -884,7 +896,7 @@ test("delete - a payload with sideloaded updates pushes the updates", function() }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [{ id: 1, name: "FIRST" }] }); post.deleteRecord(); @@ -903,6 +915,7 @@ test("delete - a payload with sideloaded updates pushes the updates", function() }); test("delete - a payload with sidloaded updates pushes the updates when the original record is omitted", function() { + adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -915,7 +928,7 @@ test("delete - a payload with sidloaded updates pushes the updates when the orig }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ posts: [{ id: 2, name: "The Parley Letter" }] }); post.deleteRecord(); @@ -1387,6 +1400,7 @@ test("findMany - findMany does not coalesce by default", function() { }); test("findMany - returning an array populates the array", function() { + adapter.shouldBackgroundReloadRecord = () => false; Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); adapter.coalesceFindRequests = true; @@ -1411,7 +1425,7 @@ test("findMany - returning an array populates the array", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1439,6 +1453,7 @@ test("findMany - returning an array populates the array", function() { }); test("findMany - returning sideloaded data loads the data", function() { + adapter.shouldBackgroundReloadRecord = () => false; Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); adapter.coalesceFindRequests = true; @@ -1463,7 +1478,7 @@ test("findMany - returning sideloaded data loads the data", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1494,6 +1509,7 @@ test("findMany - returning sideloaded data loads the data", function() { }); test("findMany - a custom serializer is used if present", function() { + adapter.shouldBackgroundReloadRecord = () => false; env.registry.register('serializer:post', DS.RESTSerializer.extend({ primaryKey: '_ID_', attrs: { name: '_NAME_' } @@ -1528,7 +1544,7 @@ test("findMany - a custom serializer is used if present", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { _ID_: 1, _NAME_: "FIRST" }, @@ -1551,6 +1567,7 @@ test("findMany - a custom serializer is used if present", function() { }); test("findHasMany - returning an array populates the array", function() { + adapter.shouldBackgroundReloadRecord = () => false; Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); run(function() { @@ -1572,7 +1589,7 @@ test("findHasMany - returning an array populates the array", function() { }); }); - run(store, 'find', 'post', '1').then(async(function(post) { + run(store, 'findRecord', 'post', '1').then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1600,6 +1617,7 @@ test("findHasMany - returning an array populates the array", function() { }); test("findHasMany - passes buildURL the requestType", function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.buildURL = function(type, id, snapshot, requestType) { equal(requestType, 'findHasMany'); }; @@ -1625,7 +1643,7 @@ test("findHasMany - passes buildURL the requestType", function() { }); }); - run(store, 'find', 'post', '1').then(async(function(post) { + run(store, 'findRecord', 'post', '1').then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1643,6 +1661,7 @@ test("findHasMany - passes buildURL the requestType", function() { test("findMany - returning sideloaded data loads the data", function() { + adapter.shouldBackgroundReloadRecord = () => false; Post.reopen({ comments: DS.hasMany('comment', { async: true }) }); adapter.coalesceFindRequests = true; @@ -1665,7 +1684,7 @@ test("findMany - returning sideloaded data loads the data", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1689,6 +1708,7 @@ test("findMany - returning sideloaded data loads the data", function() { }); test("findMany - a custom serializer is used if present", function() { + adapter.shouldBackgroundReloadRecord = () => false; env.registry.register('serializer:post', DS.RESTSerializer.extend({ primaryKey: '_ID_', attrs: { name: '_NAME_' } @@ -1720,7 +1740,7 @@ test("findMany - a custom serializer is used if present", function() { }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { _ID_: 1, _NAME_: "FIRST" }, @@ -1743,6 +1763,7 @@ test("findMany - a custom serializer is used if present", function() { }); test('findBelongsTo - passes buildURL the requestType', function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.buildURL = function(type, id, snapshot, requestType) { equal(requestType, 'findBelongsTo'); }; @@ -1768,7 +1789,7 @@ test('findBelongsTo - passes buildURL the requestType', function() { }); }); - run(store, 'find', 'comment', 1).then(async(function(comment) { + run(store, 'findRecord', 'comment', 1).then(async(function(comment) { ajaxResponse({ post: { id: 1, name: 'Rails is omakase' } }); return comment.get('post'); })).then(async(function(post) { diff --git a/packages/ember-data/tests/integration/adapter/store-adapter-test.js b/packages/ember-data/tests/integration/adapter/store-adapter-test.js index 2de35c23a9b..1dd7a73dc18 100644 --- a/packages/ember-data/tests/integration/adapter/store-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/store-adapter-test.js @@ -69,7 +69,7 @@ test("Records loaded multiple times and retrieved in recordArray are ready to se test("by default, createRecords calls createRecord once per record", function() { var count = 1; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.createRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -114,7 +114,7 @@ test("by default, createRecords calls createRecord once per record", function() test("by default, updateRecords calls updateRecord once per record", function() { var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -180,7 +180,7 @@ test("by default, updateRecords calls updateRecord once per record", function() test("calling store.didSaveRecord can provide an optional hash", function() { var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -244,7 +244,7 @@ test("by default, deleteRecord calls deleteRecord once per record", function() { expect(4); var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -302,7 +302,7 @@ test("by default, destroyRecord calls deleteRecord once per record without requi expect(4); var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -357,7 +357,7 @@ test("if an existing model is edited then deleted, deleteRecord is called on the expect(5); var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { count++; equal(snapshot.id, 'deleted-record', "should pass correct record to deleteRecord"); @@ -401,6 +401,7 @@ test("if a deleted record errors, it enters the error state", function() { var count = 0; var error = new DS.AdapterError(); + adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { if (count++ === 0) { return Ember.RSVP.reject(error); @@ -588,6 +589,7 @@ test("if a created record is marked as erred by the server, it enters an error s }); test("if an updated record is marked as invalid by the server, it enters an error state", function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); @@ -643,6 +645,7 @@ test("if an updated record is marked as invalid by the server, it enters an erro test("records can have errors on arbitrary properties after update", function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { if (snapshot.attr('name').indexOf('Bro') === -1) { return Ember.RSVP.reject(new DS.InvalidError({ base: ['is a generally unsavoury character'] })); @@ -702,6 +705,7 @@ test("records can have errors on arbitrary properties after update", function() test("if an updated record is marked as invalid by the server, you can attempt the save again", function() { var saveCount = 0; + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { equal(type, Person, "the type is correct"); saveCount++; @@ -762,6 +766,7 @@ test("if an updated record is marked as invalid by the server, you can attempt t test("if a updated record is marked as erred by the server, it enters an error state", function() { var error = new DS.AdapterError(); + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { return Ember.RSVP.reject(error); }; @@ -803,6 +808,7 @@ test("can be created after the DS.Store", function() { }); test("the filter method can optionally take a server query as well", function() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.query = function(store, type, query, array) { return Ember.RSVP.resolve([ { id: 1, name: "Yehuda Katz" }, @@ -894,6 +900,7 @@ test("relationships returned via `commit` do not trigger additional findManys", }); test("relationships don't get reset if the links is the same", function() { + adapter.shouldBackgroundReloadRecord = () => false; Person.reopen({ dogs: DS.hasMany({ async: true }) }); diff --git a/packages/ember-data/tests/integration/debug-adapter-test.js b/packages/ember-data/tests/integration/debug-adapter-test.js index 19801b3f6fa..29465089cdd 100644 --- a/packages/ember-data/tests/integration/debug-adapter-test.js +++ b/packages/ember-data/tests/integration/debug-adapter-test.js @@ -8,8 +8,10 @@ module("DS.DebugAdapter", { App = Ember.Application.create(); App.toString = function() { return 'App'; }; - App.StoreService = DS.Store.extend({ - adapter: DS.Adapter.extend() + App.StoreService = DS.Store.extend({}); + + App.ApplicationAdapter = DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false }); App.Post = DS.Model.extend({ diff --git a/packages/ember-data/tests/integration/filter-test.js b/packages/ember-data/tests/integration/filter-test.js index eb377062a4f..a9e8cf0b0d1 100644 --- a/packages/ember-data/tests/integration/filter-test.js +++ b/packages/ember-data/tests/integration/filter-test.js @@ -213,7 +213,8 @@ test("a Record Array can update its filter", function() { customAdapter(env, DS.Adapter.extend({ deleteRecord: function(store, type, snapshot) { return Ember.RSVP.resolve(); - } + }, + shouldBackgroundReloadRecord: () => false })); run(function() { @@ -286,7 +287,8 @@ test("a Record Array can update its filter and notify array observers", function customAdapter(env, DS.Adapter.extend({ deleteRecord: function(store, type, snapshot) { return Ember.RSVP.resolve(); - } + }, + shouldBackgroundReloadRecord: () => false })); run(function() { @@ -382,6 +384,9 @@ test("a Record Array can update its filter and notify array observers", function }); test("it is possible to filter by computed properties", function() { + customAdapter(env, DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + })); Person.reopen({ name: DS.attr('string'), upperName: Ember.computed(function() { @@ -422,6 +427,9 @@ test("it is possible to filter by computed properties", function() { }); test("a filter created after a record is already loaded works", function() { + customAdapter(env, DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + })); Person.reopen({ name: DS.attr('string'), upperName: Ember.computed(function() { @@ -514,7 +522,8 @@ test("it is possible to filter loaded records by dirtiness", function() { customAdapter(env, DS.Adapter.extend({ updateRecord: function() { return Ember.RSVP.resolve(); - } + }, + shouldBackgroundReloadRecord: () => false })); var filter = store.filter('person', function(person) { @@ -555,7 +564,8 @@ test("it is possible to filter created records by dirtiness", function() { customAdapter(env, DS.Adapter.extend({ createRecord: function() { return Ember.RSVP.resolve(); - } + }, + shouldBackgroundReloadRecord: () => false })); }); @@ -662,7 +672,8 @@ test("a Record Array can update its filter after server-side updates one record" setup({ updateRecord: function(store, type, snapshot) { return Ember.RSVP.resolve({ id: 1, name: "Scumbag Server-side Dale" }); - } + }, + shouldBackgroundReloadRecord: () => false }); clientEdits([1]); @@ -681,7 +692,8 @@ test("a Record Array can update its filter after server-side updates multiple re case "2": return Ember.RSVP.resolve({ id: 2, name: "Scumbag Server-side Katz" }); } - } + }, + shouldBackgroundReloadRecord: () => false }); clientEdits([1,2]); @@ -745,6 +757,9 @@ test("a Record Array can update its filter after server-side creates multiple re test("destroying filteredRecordArray unregisters models from being filtered", function() { var filterFn = tapFn(function() { return true; }); + customAdapter(env, DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + })); run(function () { store.push({ data: [{ diff --git a/packages/ember-data/tests/integration/multiple_stores_test.js b/packages/ember-data/tests/integration/multiple_stores_test.js index 15b383fd854..0b9898d8f38 100644 --- a/packages/ember-data/tests/integration/multiple_stores_test.js +++ b/packages/ember-data/tests/integration/multiple_stores_test.js @@ -41,6 +41,10 @@ module("integration/multiple_stores - Multiple Stores Tests", { }); test("should be able to push into multiple stores", function() { + env.registry.register('adapter:home-planet', DS.RESTAdapter.extend({ + shouldBackgroundReloadRecord: () => false + })); + var home_planet_main = { id: '1', name: 'Earth' }; var home_planet_a = { id: '1', name: 'Mars' }; var home_planet_b = { id: '1', name: 'Saturn' }; @@ -51,15 +55,15 @@ test("should be able to push into multiple stores", function() { env.store_b.push(env.store_b.normalize('home-planet', home_planet_b)); }); - run(env.store, 'find', 'home-planet', 1).then(async(function(homePlanet) { + run(env.store, 'findRecord', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Earth"); })); - run(env.store_a, 'find', 'home-planet', 1).then(async(function(homePlanet) { + run(env.store_a, 'findRecord', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Mars"); })); - run(env.store_b, 'find', 'home-planet', 1).then(async(function(homePlanet) { + run(env.store_b, 'findRecord', 'home-planet', 1).then(async(function(homePlanet) { equal(homePlanet.get('name'), "Saturn"); })); diff --git a/packages/ember-data/tests/integration/records/reload-test.js b/packages/ember-data/tests/integration/records/reload-test.js index 48cc21dd6c7..2fa27105a5b 100644 --- a/packages/ember-data/tests/integration/records/reload-test.js +++ b/packages/ember-data/tests/integration/records/reload-test.js @@ -91,6 +91,9 @@ test("When a record is reloaded and fails, it can try again", function() { }); test("When a record is loaded a second time, isLoaded stays true", function() { + env.adapter.findRecord = function(store, type, id, snapshot) { + return { id: 1, name: "Tom Dale" }; + }; run(function() { env.store.push({ data: { diff --git a/packages/ember-data/tests/integration/records/unload-test.js b/packages/ember-data/tests/integration/records/unload-test.js index b72c3df5b65..786d23fbb00 100644 --- a/packages/ember-data/tests/integration/records/unload-test.js +++ b/packages/ember-data/tests/integration/records/unload-test.js @@ -226,6 +226,10 @@ test("unloading all records also updates record array from peekAll()", function( test("unloading a record also clears its relationship", function() { var adam, bob; + + // disable background reloading so we do not re-create the relationship. + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { env.store.push({ data: { @@ -266,7 +270,7 @@ test("unloading a record also clears its relationship", function() { }); run(function() { - env.store.find('person', 1).then(function(person) { + env.store.findRecord('person', 1).then(function(person) { equal(person.get('cars.length'), 1, 'The inital length of cars is correct'); run(function() { @@ -280,6 +284,9 @@ test("unloading a record also clears its relationship", function() { test("unloading a record also clears the implicit inverse relationships", function() { var adam, bob; + // disable background reloading so we do not re-create the relationship. + env.adapter.shouldBackgroundReloadRecord = () => false; + run(function() { env.store.push({ data: { @@ -311,7 +318,7 @@ test("unloading a record also clears the implicit inverse relationships", functi }); run(function() { - env.store.find('group', 1).then(function(group) { + env.store.findRecord('group', 1).then(function(group) { equal(group.get('people.length'), 1, 'The inital length of people is correct'); var person = env.store.peekRecord('person', 1); run(function() { diff --git a/packages/ember-data/tests/integration/relationships/belongs-to-test.js b/packages/ember-data/tests/integration/relationships/belongs-to-test.js index bce58c70fd3..3c48f8627c1 100644 --- a/packages/ember-data/tests/integration/relationships/belongs-to-test.js +++ b/packages/ember-data/tests/integration/relationships/belongs-to-test.js @@ -105,7 +105,7 @@ test("The store can materialize a non loaded monomorphic belongsTo association", inverse: 'messages' }) }); - + env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.findRecord = function(store, type, id, snapshot) { ok(true, "The adapter's find method should be called"); return Ember.RSVP.resolve({ @@ -139,7 +139,7 @@ test("The store can materialize a non loaded monomorphic belongsTo association", test("Only a record of the same type can be used with a monomorphic belongsTo relationship", function() { expect(1); - + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -169,6 +169,7 @@ test("Only a record of the same type can be used with a monomorphic belongsTo re }); test("Only a record of the same base type can be used with a polymorphic belongsTo relationship", function() { + env.adapter.shouldBackgroundReloadRecord = () => false; expect(1); run(function() { store.push({ @@ -219,6 +220,7 @@ test("Only a record of the same base type can be used with a polymorphic belongs }); test("The store can load a polymorphic belongsTo association", function() { + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ data: { @@ -254,6 +256,7 @@ test("The store can load a polymorphic belongsTo association", function() { }); test("The store can serialize a polymorphic belongsTo association", function() { + env.adapter.shouldBackgroundReloadRecord = () => false; var serializerInstance = store.serializerFor('comment'); serializerInstance.serializePolymorphicType = function(record, json, relationship) { @@ -291,6 +294,7 @@ test("The store can serialize a polymorphic belongsTo association", function() { }); test("A serializer can materialize a belongsTo as a link that gets sent back to findBelongsTo", function() { + env.adapter.shouldBackgroundReloadRecord = () => false; var Group = DS.Model.extend({ people: DS.hasMany('person', { async: false }) }); @@ -341,6 +345,7 @@ test("A serializer can materialize a belongsTo as a link that gets sent back to }); test('A record with an async belongsTo relationship always returns a promise for that relationship', function () { + env.adapter.shouldBackgroundReloadRecord = () => false; var Seat = DS.Model.extend({ person: DS.belongsTo('person', { async: false }) }); @@ -391,6 +396,7 @@ test('A record with an async belongsTo relationship always returns a promise for test("A record with an async belongsTo relationship returning null should resolve null", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; var Group = DS.Model.extend({ people: DS.hasMany('person', { async: false }) }); @@ -436,6 +442,7 @@ test("A record with an async belongsTo relationship returning null should resolv test("A record can be created with a resolved belongsTo promise", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; var Group = DS.Model.extend({ people: DS.hasMany('person', { async: false }) }); diff --git a/packages/ember-data/tests/integration/relationships/has-many-test.js b/packages/ember-data/tests/integration/relationships/has-many-test.js index 37ddc6e69f1..7e02af05c75 100644 --- a/packages/ember-data/tests/integration/relationships/has-many-test.js +++ b/packages/ember-data/tests/integration/relationships/has-many-test.js @@ -96,6 +96,10 @@ test("When a hasMany relationship is accessed, the adapter's findMany method sho ok(false, "The adapter's find method should not be called"); }; + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1, comments: [1] }; + }; + run(function() { env.store.push({ data: { @@ -133,6 +137,10 @@ test("adapter.findMany only gets unique IDs even if duplicate IDs are present in ]); }; + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1, chapters: [2, 3, 3] }; + }; + run(function() { env.store.push({ data: { @@ -753,6 +761,10 @@ test("When a polymorphic hasMany relationship is accessed, the adapter's findMan ok(false, "The adapter's find method should not be called"); }; + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1, messages: [{ id: 1, type: 'post' }, { id: 3, type: 'comment' }] }; + }; + run(function() { env.store.push({ data: { @@ -789,7 +801,7 @@ test("When a polymorphic hasMany relationship is accessed, the store can call mu User.reopen({ messages: hasMany('message', { polymorphic: true, async: true }) }); - + env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.findRecord = function(store, type, id, snapshot) { if (type === Post) { return Ember.RSVP.resolve({ id: 1 }); @@ -848,6 +860,11 @@ test("polymorphic hasMany type-checks check the superclass when MODEL_FACTORY_IN test("Type can be inferred from the key of a hasMany relationship", function() { expect(1); + + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1, contacts: [1] }; + }; + run(function() { env.store.push({ data: { @@ -877,11 +894,16 @@ test("Type can be inferred from the key of a hasMany relationship", function() { }); test("Type can be inferred from the key of an async hasMany relationship", function() { + expect(1); + User.reopen({ contacts: DS.hasMany({ async: true }) }); - expect(1); + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1, contacts: [1] }; + }; + run(function() { env.store.push({ data: { @@ -915,6 +937,10 @@ test("Polymorphic relationships work with a hasMany whose type is inferred", fun contacts: DS.hasMany({ polymorphic: true, async: false }) }); + env.adapter.findRecord = function(store, type, ids, snapshots) { + return { id: 1 }; + }; + expect(1); run(function() { env.store.push({ @@ -972,6 +998,7 @@ test("Polymorphic relationships with a hasMany is set up correctly on both sides }); test("A record can't be created from a polymorphic hasMany relationship", function() { + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ data: { @@ -999,6 +1026,7 @@ test("A record can't be created from a polymorphic hasMany relationship", functi test("Only records of the same type can be added to a monomorphic hasMany relationship", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ data: [{ @@ -1030,6 +1058,7 @@ test("Only records of the same type can be added to a monomorphic hasMany relati test("Only records of the same base type can be added to a polymorphic hasMany relationship", function() { expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ data: [{ @@ -1090,7 +1119,7 @@ test("Only records of the same base type can be added to a polymorphic hasMany r test("A record can be removed from a polymorphic association", function() { expect(4); - + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ data: { @@ -1965,7 +1994,9 @@ test("adding and removing records from hasMany relationship #2666", function() { env = setupStore({ post: Post, comment: Comment, - adapter: DS.RESTAdapter + adapter: DS.RESTAdapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); env.registry.register('adapter:comment', DS.RESTAdapter.extend({ diff --git a/packages/ember-data/tests/integration/store-test.js b/packages/ember-data/tests/integration/store-test.js index e8beb8c1a42..c1ade3cc685 100644 --- a/packages/ember-data/tests/integration/store-test.js +++ b/packages/ember-data/tests/integration/store-test.js @@ -112,6 +112,7 @@ asyncTest("find calls do not resolve when the store is destroyed", function() { test("destroying the store correctly cleans everything up", function() { var car, person; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: [{ @@ -305,8 +306,8 @@ test("Using store#findAll with no records triggers a query", function() { }); }); -test("Using store#findAll with existing records performs a query, updating existing records and returning new ones", function() { - expect(3); +test("Using store#findAll with existing records performs a query in the background, updating existing records and returning new ones", function() { + expect(4); run(function() { store.push({ @@ -339,15 +340,20 @@ test("Using store#findAll with existing records performs a query, updating exist run(function() { store.findAll('car').then(function(cars) { - equal(cars.get('length'), 2, 'There is 2 cars in the store now'); - var mini = cars.findBy('id', '1'); - equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); + equal(cars.get('length'), 1, 'Store resolves with the existing records'); }); }); + + run(function() { + var cars = store.peekAll('car'); + equal(cars.get('length'), 2, 'There is 2 cars in the store now'); + var mini = cars.findBy('id', '1'); + equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); + }); }); -test("store#findAll should return all known records even if they are not in the adapter response", function() { - expect(4); +test("store#findAll should eventually return all known records even if they are not in the adapter response", function() { + expect(5); run(function() { store.push({ @@ -383,15 +389,23 @@ test("store#findAll should return all known records even if they are not in the run(function() { store.findAll('car').then(function(cars) { equal(cars.get('length'), 2, 'It returns all cars'); - var mini = cars.findBy('id', '1'); - equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); var carsInStore = store.peekAll('car'); equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); }); }); + + run(function() { + var cars = store.peekAll('car'); + var mini = cars.findBy('id', '1'); + equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); + + var carsInStore = store.peekAll('car'); + equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); + }); }); + test("Using store#fetch on an empty record calls find", function() { expect(2); diff --git a/packages/ember-data/tests/integration/store/query-record-test.js b/packages/ember-data/tests/integration/store/query-record-test.js index 25d98c806a6..87c26a518bd 100644 --- a/packages/ember-data/tests/integration/store/query-record-test.js +++ b/packages/ember-data/tests/integration/store/query-record-test.js @@ -56,9 +56,9 @@ test("When a record is requested, and the promise is rejected, .queryRecord() is })); run(function() { - store.queryRecord('person', {}).then(null, async(function(reason) { + store.queryRecord('person', {}).catch(function(reason) { ok(true, "The rejection handler was called"); - })); + }); }); }); diff --git a/packages/ember-data/tests/unit/model-test.js b/packages/ember-data/tests/unit/model-test.js index 2a5c7ac8e7b..c4a8352e07a 100644 --- a/packages/ember-data/tests/unit/model-test.js +++ b/packages/ember-data/tests/unit/model-test.js @@ -38,7 +38,7 @@ test("can have a property set on it", function() { test("setting a property on a record that has not changed does not cause it to become dirty", function() { expect(2); - + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ data: { @@ -64,6 +64,7 @@ test("setting a property on a record that has not changed does not cause it to b test("resetting a property on a record cause it to become clean again", function() { expect(3); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -88,6 +89,7 @@ test("resetting a property on a record cause it to become clean again", function test("a record becomes clean again only if all changed properties are reset", function() { expect(5); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -116,6 +118,7 @@ test("a record becomes clean again only if all changed properties are reset", fu test("a record reports its unique id via the `id` property", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -132,6 +135,7 @@ test("a record reports its unique id via the `id` property", function() { test("a record's id is included in its toString representation", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -174,6 +178,7 @@ test("trying to set an `id` attribute should raise", function() { test("a collision of a record's id with object function's name", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; var hasWatchMethod = Object.prototype.watch; try { @@ -431,6 +436,7 @@ module("unit/model - DS.Model updating", { test("a DS.Model can update its attributes", function() { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.findRecord('person', 2).then(function(person) { @@ -562,6 +568,7 @@ test("setting a property to undefined on a newly created record should not impac // thrown out if/when the current `_attributes` hash logic is removed. test("setting a property back to its original value removes the property from the `_attributes` hash", function() { expect(3); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.findRecord('person', 1).then(function(person) { @@ -706,9 +713,8 @@ var converts = function(type, provided, expected) { run(function() { testStore.push(testStore.normalize('model', { id: 1, name: provided })); testStore.push(testStore.normalize('model', { id: 2 })); - testStore.findRecord('model', 1).then(function(record) { - deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); - }); + var record = testStore.peekRecord('model', 1); + deepEqual(get(record, 'name'), expected, type + " coerces " + provided + " to " + expected); }); // See: Github issue #421 @@ -730,7 +736,12 @@ var convertsFromServer = function(type, provided, expected) { container = new Ember.Container(); registry = container; } - var testStore = createStore({ model: Model }); + var testStore = createStore({ + model: Model, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) + }); run(function() { testStore.push(testStore.normalize('model', { id: "1", name: provided })); @@ -745,7 +756,12 @@ var convertsWhenSet = function(type, provided, expected) { name: DS.attr(type) }); - var testStore = createStore({ model: Model }); + var testStore = createStore({ + model: Model, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) + }); run(function() { testStore.push({ @@ -813,7 +829,10 @@ test("a DS.Model can describe Date attributes", function() { }); var store = createStore({ - person: Person + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); run(function() { diff --git a/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js b/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js index 7f1e07689c4..d5c0daf7f03 100644 --- a/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js +++ b/packages/ember-data/tests/unit/model/relationships/belongs-to-test.js @@ -20,6 +20,7 @@ test("belongsTo lazily loads relationships as needed", function() { var env = setupStore({ tag: Tag, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -149,12 +150,11 @@ test("async belongsTo relationships work when the data hash has already been loa }); run(function() { - store.findRecord('person', 1).then(async(function(person) { - equal(get(person, 'name'), "Tom Dale", "The person is now populated"); - return run(function() { - return get(person, 'tag'); - }); - })).then(async(function(tag) { + var person = store.peekRecord('person', 1); + equal(get(person, 'name'), "Tom Dale", "The person is now populated"); + return run(function() { + return get(person, 'tag'); + }).then(async(function(tag) { equal(get(tag, 'name'), "friendly", "Tom Dale is now friendly"); equal(get(tag, 'isLoaded'), true, "Tom Dale is now loaded"); })); @@ -176,6 +176,7 @@ test("calling createRecord and passing in an undefined value for a relationship var env = setupStore({ tag: Tag, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.createRecord('person', { id: 1, tag: undefined }); @@ -205,6 +206,7 @@ test("When finding a hasMany relationship the inverse belongsTo relationship is var env = setupStore({ occupation: Occupation, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; env.adapter.findMany = function(store, type, ids, snapshots) { equal(snapshots[0].belongsTo('person').id, '1'); @@ -312,6 +314,7 @@ test("belongsTo supports relationships to models with id 0", function() { var env = setupStore({ tag: Tag, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -375,6 +378,7 @@ test("belongsTo gives a warning when provided with a serialize option", function var env = setupStore({ hobby: Hobby, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ @@ -428,6 +432,7 @@ test("belongsTo gives a warning when provided with an embedded option", function var env = setupStore({ hobby: Hobby, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ diff --git a/packages/ember-data/tests/unit/model/relationships/has-many-test.js b/packages/ember-data/tests/unit/model/relationships/has-many-test.js index 917c6c3dc6b..20ea68b7724 100644 --- a/packages/ember-data/tests/unit/model/relationships/has-many-test.js +++ b/packages/ember-data/tests/unit/model/relationships/has-many-test.js @@ -38,6 +38,7 @@ test("hasMany handles pre-loaded relationships", function() { ok(false, "findRecord() should not be called with these values"); } }; + env.adapter.shouldBackgroundReloadRecord = () => false; var store = env.store; @@ -235,6 +236,7 @@ test("hasMany lazily loads async relationships", function() { ok(false, "findRecord() should not be called with these values"); } }; + env.adapter.shouldBackgroundReloadRecord = () => false; var store = env.store; @@ -411,6 +413,7 @@ test("relationships work when declared with a string path", function() { person: Person, tag: Tag }); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.push({ @@ -525,6 +528,7 @@ test("it is possible to add a new item to a relationship", function() { tag: Tag, person: Person }); + env.adapter.shouldBackgroundReloadRecord = () => false; var store = env.store; @@ -656,6 +660,7 @@ test("it is possible to remove an item from a relationship", function() { var env = setupStore({ tag: Tag, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ diff --git a/packages/ember-data/tests/unit/model/relationships/record-array-test.js b/packages/ember-data/tests/unit/model/relationships/record-array-test.js index f4ad4bc0593..bbe730f8f67 100644 --- a/packages/ember-data/tests/unit/model/relationships/record-array-test.js +++ b/packages/ember-data/tests/unit/model/relationships/record-array-test.js @@ -66,6 +66,7 @@ test("can create child record from a hasMany relationship", function() { var env = setupStore({ tag: Tag, person: Person }); var store = env.store; + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({ diff --git a/packages/ember-data/tests/unit/record-array-test.js b/packages/ember-data/tests/unit/record-array-test.js index 8f9b8343029..45069ff45c2 100644 --- a/packages/ember-data/tests/unit/record-array-test.js +++ b/packages/ember-data/tests/unit/record-array-test.js @@ -17,7 +17,10 @@ test("a record array is backed by records", function() { expect(3); var store = createStore({ - person: Person + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); run(function() { store.push({ @@ -146,7 +149,8 @@ test("a loaded record is removed from a record array when it is deleted", functi tag: Tag, person: Person, adapter: DS.Adapter.extend({ - deleteRecord: () => Ember.RSVP.resolve() + deleteRecord: () => Ember.RSVP.resolve(), + shouldBackgroundReloadRecord: () => false }) }); var store = env.store; diff --git a/packages/ember-data/tests/unit/store/adapter-interop-test.js b/packages/ember-data/tests/unit/store/adapter-interop-test.js index 4129a29c3d5..bc7e6a08037 100644 --- a/packages/ember-data/tests/unit/store/adapter-interop-test.js +++ b/packages/ember-data/tests/unit/store/adapter-interop-test.js @@ -4,7 +4,7 @@ var resolve = Ember.RSVP.resolve; var TestAdapter, store, person; var run = Ember.run; -module("unit/store/adapter_interop - DS.Store working with a DS.Adapter", { +module("unit/store/adapter-interop - DS.Store working with a DS.Adapter", { setup: function() { TestAdapter = DS.Adapter.extend(); }, @@ -108,7 +108,7 @@ test("Returning a promise from `findRecord` asynchronously loads data", function }); test("IDs provided as numbers are coerced to strings", function() { - expect(4); + expect(5); var adapter = TestAdapter.extend({ findRecord: function(store, type, id, snapshot) { @@ -152,7 +152,10 @@ test("can load data for the same record if it is not dirty", function() { }); var store = createStore({ - person: Person + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); run(function() { @@ -379,7 +382,10 @@ test("if an id is supplied in the initial data hash, it can be looked up using ` name: DS.attr('string') }); var store = createStore({ - person: Person + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); var person; @@ -893,6 +899,7 @@ test("store should not reload record when shouldReloadRecord returns false", fun ok(true, 'shouldReloadRecord should be called when the record is in the store'); return false; }, + shouldBackgroundReloadRecord: () => false, findRecord: function() { ok(false, 'find should not be called when shouldReloadRecord returns false'); } diff --git a/packages/ember-data/tests/unit/store/push-test.js b/packages/ember-data/tests/unit/store/push-test.js index 9f38f2d7516..2dae0dee130 100644 --- a/packages/ember-data/tests/unit/store/push-test.js +++ b/packages/ember-data/tests/unit/store/push-test.js @@ -50,6 +50,7 @@ module("unit/store/push - DS.Store#push", { test("Calling push with a normalized hash returns a record", function() { expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { var person = store.push({ @@ -75,6 +76,7 @@ test("Calling push with a normalized hash returns a record", function() { test("Supplying a model class for `push` is the same as supplying a string", function () { expect(1); + env.adapter.shouldBackgroundReloadRecord = () => false; var Programmer = Person.extend(); env.registry.register('model:programmer', Programmer); @@ -126,6 +128,7 @@ test("Calling push triggers `didLoad` even if the record hasn't been requested f test("Calling push with partial records updates just those attributes", function() { expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { store.push({