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 ab5b937e889..f60df327682 100644 --- a/packages/ember-data/tests/integration/adapter/find-test.js +++ b/packages/ember-data/tests/integration/adapter/find-test.js @@ -37,18 +37,6 @@ test("It raises an assertion when `undefined` is passed as id (#1705)", function }, "You may not 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 d9a18ce30cf..24e55e0eab3 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; }, @@ -50,11 +55,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 30b46b6df77..24b96a61eb2 100644 --- a/packages/ember-data/tests/integration/adapter/rest-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/rest-adapter-test.js @@ -392,11 +392,11 @@ test("create - a record on the many side of a hasMany relationship should update name: "Another Comment", post: 1 }, - { - id: "1", - name: "Dat Parley Letter", - post: 1 - }] + { + id: "1", + name: "Dat Parley Letter", + post: 1 + }] // My API is returning a comment:{} as well as a comments:[{...},...] //, comment: { // id: "2", @@ -527,46 +527,51 @@ test("update - an empty payload is a basic success", function() { store.push('post', { id: 1, name: "Rails is omakase" }); }); - 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('post', { id: 1, name: "Rails is omakase" }); }); - 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('post', { id: 1, name: "Rails is omakase" }); }); - 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"); @@ -582,11 +587,12 @@ 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('post', { id: 1, name: "Rails is omakase" }); }); - 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"); @@ -625,11 +631,12 @@ 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('post', { id: 1, name: "Rails is omakase" }); }); - 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" }] @@ -651,6 +658,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_', @@ -664,7 +672,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) { @@ -675,6 +683,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('post', { id: 1, name: "Not everyone uses Rails", comments: [1] }); @@ -686,8 +695,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'); @@ -704,11 +713,12 @@ 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('post', { id: 1, name: "Rails is omakase" }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse(); post.deleteRecord(); @@ -724,6 +734,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; }; @@ -732,7 +743,7 @@ test("delete - passes the requestType to buildURL", function() { store.push('post', { id: 1, name: "Rails is omakase" }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse(); post.deleteRecord(); @@ -743,11 +754,12 @@ 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('post', { id: 1, name: "Rails is omakase" }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [{ id: 1, name: "FIRST" }] }); post.deleteRecord(); @@ -766,11 +778,12 @@ 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('post', { id: 1, name: "Rails is omakase" }); }); - 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(); @@ -1225,6 +1238,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; @@ -1232,7 +1246,7 @@ test("findMany - returning an array populates the array", function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1260,6 +1274,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; @@ -1267,7 +1282,7 @@ test("findMany - returning sideloaded data loads the data", function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1298,6 +1313,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_' } @@ -1315,7 +1331,7 @@ test("findMany - a custom serializer is used if present", function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - store.find('post', 1).then(async(function(post) { + store.findRecord('post', 1).then(async(function(post) { ajaxResponse({ comments: [ { _ID_: 1, _NAME_: "FIRST" }, @@ -1338,6 +1354,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() { @@ -1351,7 +1368,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" }, @@ -1379,6 +1396,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'); }; @@ -1396,7 +1414,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" }, @@ -1414,6 +1432,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; @@ -1428,7 +1447,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" }, @@ -1452,6 +1471,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_' } @@ -1475,7 +1495,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" }, @@ -1498,6 +1518,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'); }; @@ -1511,7 +1532,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 a57cb647806..8c09321a793 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"); @@ -167,7 +167,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"); @@ -218,7 +218,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"); @@ -263,7 +263,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"); @@ -305,7 +305,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"); @@ -339,7 +339,7 @@ test("if an existing model is edited then deleted, deleteRecord is called on the test("if a deleted record errors, it enters the error state", function() { var count = 0; - + adapter.shouldBackgroundReloadRecord = () => false; adapter.deleteRecord = function(store, type, snapshot) { if (count++ === 0) { return Ember.RSVP.reject(); @@ -514,6 +514,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"); @@ -560,6 +561,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'] })); @@ -610,6 +612,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++; @@ -659,6 +662,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() { + adapter.shouldBackgroundReloadRecord = () => false; adapter.updateRecord = function(store, type, snapshot) { return Ember.RSVP.reject(); }; @@ -690,6 +694,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" }, @@ -750,6 +755,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/application-test.js b/packages/ember-data/tests/integration/application-test.js index 873408bebc6..2a0a03893d8 100644 --- a/packages/ember-data/tests/integration/application-test.js +++ b/packages/ember-data/tests/integration/application-test.js @@ -42,6 +42,7 @@ module("integration/application - Injecting a Custom Store", { test("If a Store property exists on an Ember.Application, it should be instantiated.", function() { run(function() { + ok(true); ok(getStore().get('isCustom'), "the custom store was instantiated"); }); }); diff --git a/packages/ember-data/tests/integration/debug-adapter-test.js b/packages/ember-data/tests/integration/debug-adapter-test.js index 3d7034c5399..26c51457173 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 a4600eed35a..d783fab857b 100644 --- a/packages/ember-data/tests/integration/records/reload-test.js +++ b/packages/ember-data/tests/integration/records/reload-test.js @@ -82,6 +82,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('person', { id: 1, name: "Tom Dale" }); }); diff --git a/packages/ember-data/tests/integration/records/unload-test.js b/packages/ember-data/tests/integration/records/unload-test.js index b0df2e60b45..f7c8ef7f856 100644 --- a/packages/ember-data/tests/integration/records/unload-test.js +++ b/packages/ember-data/tests/integration/records/unload-test.js @@ -155,6 +155,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() { adam = env.store.push('person', { id: 1, @@ -173,7 +177,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() { @@ -187,6 +191,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() { adam = env.store.push('person', { id: 1, @@ -202,7 +209,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 b1f6d7d2e3e..fd02528fe19 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('post', { id: 1, comments: [1] }); env.store.push('comment', { id: 1 }); @@ -118,6 +122,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('book', { id: 1, chapters: [2, 3, 3] }); env.store.findRecord('book', 1).then(function(book) { @@ -613,6 +621,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('user', { id: 1, messages: [{ id: 1, type: 'post' }, { id: 3, type: 'comment' }] }); env.store.push('post', { id: 1 }); @@ -631,7 +643,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 }); @@ -677,6 +689,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('user', { id: 1, contacts: [1] }); env.store.push('contact', { id: 1 }); @@ -691,11 +708,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('user', { id: 1, contacts: [1] }); env.store.push('contact', { id: 1 }); @@ -714,6 +736,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('user', { id: 1, contacts: [{ id: 1, type: 'email' }, { id: 2, type: 'phone' }] }); @@ -753,6 +779,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('user', { id: 1, messages: [] }); }); @@ -770,6 +797,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('post', { id: 1, comments: [] }); env.store.push('post', { id: 2 }); @@ -789,6 +817,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('user', { id: 1, messages: [] }); env.store.push('user', { id: 2, messages: [] }); @@ -822,7 +851,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('user', { id: 1 , messages: [{ id: 3, type: 'comment' }] }); env.store.push('comment', { id: 3 }); @@ -1285,7 +1314,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 f5fb1526bc2..c2b4df014df 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() { car = store.push('car', { id: 1, @@ -281,8 +282,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('car', { @@ -310,15 +311,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('car', { id: 1, make: 'BMC', model: 'Mini' }); @@ -339,15 +345,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 2a43eb650c4..be58b612145 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('person', { id: 1, name: "Peter", isDrugAddict: true }); store.findRecord('person', 1).then(function(person) { @@ -54,6 +54,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('person', { id: 1, name: "Peter", isDrugAddict: true }); @@ -69,6 +70,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('person', { id: 1, name: "Peter", isDrugAddict: true }); @@ -88,6 +90,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('person', { id: 1 }); @@ -99,6 +102,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('person', { id: 1 }); @@ -128,6 +132,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 { @@ -336,6 +341,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) { @@ -467,6 +473,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) { @@ -597,9 +604,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 @@ -621,7 +627,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 })); @@ -636,7 +647,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('model', { id: 2 }); @@ -699,7 +715,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 f01b3158fec..5773657a0fb 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.pushMany('tag', [{ id: 5, name: "friendly" }, { id: 2, name: "smarmy" }, { id: 12, name: "oohlala" }]); @@ -101,12 +102,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"); })); @@ -128,6 +128,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 }); @@ -157,6 +158,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'); @@ -235,6 +237,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.pushMany('tag', [{ id: 0, name: "friendly" }, { id: 2, name: "smarmy" }, { id: 12, name: "oohlala" }]); @@ -268,6 +271,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.pushMany('hobby', [{ id: 1, name: "fishing" }, { id: 1, name: "coding" }]); @@ -297,6 +301,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.pushMany('hobby', [{ id: 1, name: "fishing" }, { id: 1, name: "coding" }]); 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 b33f4da0648..e0247636d57 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; @@ -125,6 +126,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; @@ -246,6 +248,7 @@ test("relationships work when declared with a string path", function() { person: Person, tag: Tag }); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { env.store.pushMany('tag', [{ id: 5, name: "friendly" }, { id: 2, name: "smarmy" }, { id: 12, name: "oohlala" }]); @@ -327,6 +330,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; @@ -401,6 +405,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('person', { id: 1, name: "Tom Dale", tags: [1] }); 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 3af9030e9c7..0638c491046 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 @@ -45,6 +45,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('person', { id: 1, name: "Tom Dale" }); diff --git a/packages/ember-data/tests/unit/record-array-test.js b/packages/ember-data/tests/unit/record-array-test.js index 16a4c674544..00ff5b6f473 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.pushMany('person', array); @@ -92,7 +95,10 @@ test("a loaded record is removed from a record array when it is deleted", functi var env = setupStore({ tag: Tag, - person: Person + person: Person, + adapter: DS.Adapter.extend({ + 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 9c25bb42a1c..23b6eaef59a 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) { @@ -147,7 +147,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() { @@ -181,7 +184,10 @@ test("pushMany extracts ids from an Array of hashes if no ids are specified", fu var Person = DS.Model.extend({ name: DS.attr('string') }); var store = createStore({ - person: Person + person: Person, + adapter: DS.Adapter.extend({ + shouldBackgroundReloadRecord: () => false + }) }); run(function() { @@ -359,7 +365,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; @@ -855,6 +864,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 bd10b941a5b..975c58f5aa5 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({ @@ -73,6 +74,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); @@ -128,6 +130,7 @@ test("Calling update should be deprecated", function() { test("Calling push with partial records updates just those attributes", function() { expect(2); + env.adapter.shouldBackgroundReloadRecord = () => false; run(function() { var person = store.push({