From 8021db7f0fa643dd683800d66fe84bbfe7641479 Mon Sep 17 00:00:00 2001 From: Eric Kelly Date: Thu, 4 Jun 2015 21:21:20 -0400 Subject: [PATCH 1/2] Rename & deprecate store.getById for store.peekRecord --- packages/ember-data/lib/system/store.js | 27 +++++- .../integration/adapter/rest-adapter-test.js | 90 +++++++++---------- .../non-dasherized-lookups.js | 4 +- .../tests/integration/filter-test.js | 4 +- .../tests/integration/records/unload-test.js | 2 +- .../serializers/rest-serializer-test.js | 9 +- .../unit/model/lifecycle-callbacks-test.js | 2 +- .../model/relationships/belongs-to-test.js | 2 +- .../unit/model/relationships/has-many-test.js | 6 +- .../tests/unit/store/adapter-interop-test.js | 2 +- .../tests/unit/store/get-by-id-test.js | 35 -------- .../tests/unit/store/peek-by-id-test.js | 46 ++++++++++ .../ember-data/tests/unit/store/push-test.js | 16 ++-- 13 files changed, 140 insertions(+), 105 deletions(-) delete mode 100644 packages/ember-data/tests/unit/store/get-by-id-test.js create mode 100644 packages/ember-data/tests/unit/store/peek-by-id-test.js diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index 9ae07dd64aa..f14081beb5e 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -530,7 +530,7 @@ Store = Service.extend({ Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var options = deprecatePreload(preload, this.modelFor(modelName), 'fetchById'); if (this.hasRecordForId(modelName, id)) { - return this.getById(modelName, id).reload(); + return this.peekRecord(modelName, id).reload(); } else { return this.findRecord(modelName, id, options); } @@ -801,6 +801,31 @@ Store = Service.extend({ @return {DS.Model|null} record */ getById: function(modelName, id) { + Ember.deprecate('Using store.getById() has been deprecated. Use store.peekRecord to get a record by a given type and ID without triggering a fetch.'); + return this.peekRecord(modelName, id); + }, + + /** + Get a record by a given type and ID without triggering a fetch. + + This method will synchronously return the record if it is available in the store, + otherwise it will return `null`. A record is available if it has been fetched earlier, or + pushed manually into the store. + + _Note: This is an synchronous method and does not return a promise._ + + ```js + var post = store.peekRecord('post', 1); + + post.get('id'); // 1 + ``` + + @method peekRecord + @param {String} modelName + @param {String|Integer} id + @return {DS.Model|null} record + */ + peekRecord: function(modelName, id) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); if (this.hasRecordForId(modelName, id)) { return this._internalModelForId(modelName, id).getRecord(); 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 b9810dbfce3..f80aa3978e4 100644 --- a/packages/ember-data/tests/integration/adapter/rest-adapter-test.js +++ b/packages/ember-data/tests/integration/adapter/rest-adapter-test.js @@ -99,7 +99,7 @@ test("find - payload with sideloaded records of the same type", function() { equal(post.get('id'), "1"); equal(post.get('name'), "Rails is omakase"); - var post2 = store.getById('post', 2); + var post2 = store.peekRecord('post', 2); equal(post2.get('id'), "2"); equal(post2.get('name'), "The Parley Letter"); })); @@ -119,7 +119,7 @@ test("find - payload with sideloaded records of a different type", function() { equal(post.get('id'), "1"); equal(post.get('name'), "Rails is omakase"); - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); equal(comment.get('id'), "1"); equal(comment.get('name'), "FIRST"); })); @@ -246,7 +246,7 @@ test("create - findMany doesn't overwrite owner", function() { run(function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [] }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); run(function() { comment = store.createRecord('comment', { name: "The Parley Letter" }); @@ -413,7 +413,7 @@ test("create - a record on the many side of a hasMany relationship should update store.push('comment', { id: 1, name: "Dat Parlay Letter", post: 1 }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); var commentCount = post.get('comments.length'); equal(commentCount, 1, "the post starts life with a comment"); @@ -448,8 +448,8 @@ test("create - sideloaded belongsTo relationships are both marked as loaded", fu run(function() { post.save().then(async(function(record) { - equal(store.getById('post', 1).get('comment.isLoaded'), true, "post's comment isLoaded (via store)"); - equal(store.getById('comment', 1).get('post.isLoaded'), true, "comment's post isLoaded (via store)"); + equal(store.peekRecord('post', 1).get('comment.isLoaded'), true, "post's comment isLoaded (via store)"); + equal(store.peekRecord('comment', 1).get('post.isLoaded'), true, "comment's post isLoaded (via store)"); equal(record.get('comment.isLoaded'), true, "post's comment isLoaded (via record)"); equal(record.get('comment.post.isLoaded'), true, "post's comment's post isLoaded (via record)"); })); @@ -618,7 +618,7 @@ test("update - a payload with sideloaded updates pushes the updates", function() equal(post.get('isDirty'), false, "the post isn't dirty anymore"); equal(post.get('name'), "Dat Parley Letter", "the post was updated"); - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); equal(comment.get('name'), "FIRST", "The comment was sideloaded"); })); }); @@ -645,7 +645,7 @@ test("update - a payload with sideloaded updates pushes the updates", function() equal(post.get('isDirty'), false, "the post isn't dirty anymore"); equal(post.get('name'), "Dat Parley Letter", "the post was updated"); - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); equal(comment.get('name'), "FIRST", "The comment was sideloaded"); })); }); @@ -689,7 +689,7 @@ test("update - hasMany relationships faithfully reflect simultaneous adds and re store.find('comment', 2).then(async(function() { return store.find('post', 1); })).then(async(function(post) { - var newComment = store.getById('comment', 2); + var newComment = store.peekRecord('comment', 2); var comments = post.get('comments'); // Replace the comment with a new one @@ -760,7 +760,7 @@ test("delete - a payload with sideloaded updates pushes the updates", function() equal(post.get('isDirty'), false, "the post isn't dirty anymore"); equal(post.get('isDeleted'), true, "the post is now deleted"); - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); equal(comment.get('name'), "FIRST", "The comment was sideloaded"); })); }); @@ -783,7 +783,7 @@ test("delete - a payload with sidloaded updates pushes the updates when the orig equal(post.get('isDirty'), false, "the original post isn't dirty anymore"); equal(post.get('isDeleted'), true, "the original post is now deleted"); - var newPost = store.getById('post', 2); + var newPost = store.peekRecord('post', 2); equal(newPost.get('name'), "The Parley Letter", "The new post was added to the store"); })); }); @@ -820,8 +820,8 @@ test("findAll - returning an array populates the array", function() { equal(passedVerb, "GET"); equal(passedHash.data, undefined); - var post1 = store.getById('post', 1); - var post2 = store.getById('post', 2); + var post1 = store.peekRecord('post', 1); + var post2 = store.peekRecord('post', 2); deepEqual( post1.getProperties('id', 'name'), @@ -872,7 +872,7 @@ test("findAll - returning sideloaded data loads the data", function() { comments: [{ id: 1, name: "FIRST" }] }); store.findAll('post').then(async(function(posts) { - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); deepEqual(comment.getProperties('id', 'name'), { id: "1", name: "FIRST" }); })); @@ -892,8 +892,8 @@ test("findAll - data is normalized through custom serializers", function() { }); store.findAll('post').then(async(function(posts) { - var post1 = store.getById('post', 1); - var post2 = store.getById('post', 2); + var post1 = store.peekRecord('post', 1); + var post2 = store.peekRecord('post', 2); deepEqual( post1.getProperties('id', 'name'), @@ -1078,8 +1078,8 @@ test("findQuery - returning an array populates the array", function() { equal(passedVerb, 'GET'); deepEqual(passedHash.data, { page: 1 }); - var post1 = store.getById('post', 1); - var post2 = store.getById('post', 2); + var post1 = store.peekRecord('post', 1); + var post2 = store.peekRecord('post', 2); deepEqual( post1.getProperties('id', 'name'), @@ -1112,7 +1112,7 @@ test("findQuery - returning sideloaded data loads the data", function() { }); store.query('post', { page: 1 }).then(async(function(posts) { - var comment = store.getById('comment', 1); + var comment = store.peekRecord('comment', 1); deepEqual(comment.getProperties('id', 'name'), { id: "1", name: "FIRST" }); })); @@ -1130,8 +1130,8 @@ test("findQuery - data is normalized through custom serializers", function() { }); store.query('post', { page: 1 }).then(async(function(posts) { - var post1 = store.getById('post', 1); - var post2 = store.getById('post', 2); + var post1 = store.peekRecord('post', 1); + var post2 = store.peekRecord('post', 2); deepEqual( post1.getProperties('id', 'name'), @@ -1163,7 +1163,7 @@ test("findMany - findMany uses a correct URL to access the records", function() store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1189,7 +1189,7 @@ test("findMany - passes buildURL the requestType", function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); ajaxResponse({ comments: [ { id: 1, name: "FIRST" }, @@ -1209,7 +1209,7 @@ test("findMany - findMany does not coalesce by default", function() { store.push('post', { id: 1, name: "Rails is omakase", comments: [1, 2, 3] }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); //It's still ok to return this even without coalescing because RESTSerializer supports sideloading ajaxResponse({ comments: [ @@ -1243,9 +1243,9 @@ test("findMany - returning an array populates the array", function() { return post.get('comments'); })).then(async(function(comments) { - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); deepEqual(comment1.getProperties('id', 'name'), { id: "1", name: "FIRST" }); deepEqual(comment2.getProperties('id', 'name'), { id: "2", name: "Rails is unagi" }); @@ -1280,11 +1280,11 @@ test("findMany - returning sideloaded data loads the data", function() { return post.get('comments'); })).then(async(function(comments) { - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); - var comment4 = store.getById('comment', 4); - var post2 = store.getById('post', 2); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); + var comment4 = store.peekRecord('comment', 4); + var post2 = store.peekRecord('post', 2); deepEqual( comments.toArray(), @@ -1325,9 +1325,9 @@ test("findMany - a custom serializer is used if present", function() { return post.get('comments'); })).then(async(function(comments) { - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); deepEqual(comment1.getProperties('id', 'name'), { id: "1", name: "FIRST" }); deepEqual(comment2.getProperties('id', 'name'), { id: "2", name: "Rails is unagi" }); @@ -1366,9 +1366,9 @@ test("findHasMany - returning an array populates the array", function() { equal(passedVerb, 'GET'); equal(passedHash, undefined); - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); deepEqual(comment1.getProperties('id', 'name'), { id: "1", name: "FIRST" }); deepEqual(comment2.getProperties('id', 'name'), { id: "2", name: "Rails is unagi" }); @@ -1440,10 +1440,10 @@ test("findMany - returning sideloaded data loads the data", function() { return post.get('comments'); })).then(async(function(comments) { - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); - var post2 = store.getById('post', 2); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); + var post2 = store.peekRecord('post', 2); deepEqual(comments.toArray(), [comment1, comment2, comment3], "The correct records are in the array"); @@ -1485,9 +1485,9 @@ test("findMany - a custom serializer is used if present", function() { }); return post.get('comments'); })).then(async(function(comments) { - var comment1 = store.getById('comment', 1); - var comment2 = store.getById('comment', 2); - var comment3 = store.getById('comment', 3); + var comment1 = store.peekRecord('comment', 1); + var comment2 = store.peekRecord('comment', 2); + var comment3 = store.peekRecord('comment', 3); deepEqual(comment1.getProperties('id', 'name'), { id: "1", name: "FIRST" }); deepEqual(comment2.getProperties('id', 'name'), { id: "2", name: "Rails is unagi" }); diff --git a/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js b/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js index e72eacff39c..e026bea16d5 100644 --- a/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js +++ b/packages/ember-data/tests/integration/backwards-compat/non-dasherized-lookups.js @@ -92,7 +92,7 @@ test('looks up using camelCase string', function() { run(function() { store.find('postNote', 1).then(function(postNote) { - equal(postNote.get('notePost'), store.getById('notePost', 1)); + equal(postNote.get('notePost'), store.peekRecord('notePost', 1)); }); }); }); @@ -114,7 +114,7 @@ test('looks up using under_score string', function() { run(function() { store.find('long_model_name', 1).then(function(longModelName) { - deepEqual(longModelName.get('postNotes').toArray(), [store.getById('postNote', 1)]); + deepEqual(longModelName.get('postNotes').toArray(), [store.peekRecord('postNote', 1)]); }); }); diff --git a/packages/ember-data/tests/integration/filter-test.js b/packages/ember-data/tests/integration/filter-test.js index 9d6503a4f6b..3102b0593be 100644 --- a/packages/ember-data/tests/integration/filter-test.js +++ b/packages/ember-data/tests/integration/filter-test.js @@ -109,8 +109,8 @@ test("when a DS.Model updates its relationships, its changes affect its filtered equal(get(people, 'length'), 0, "there are now 0 items"); - var erik = store.getById('person', 3); - var yehuda = store.getById('person', 2); + var erik = store.peekRecord('person', 3); + var yehuda = store.peekRecord('person', 2); run(function() { erik.set('bestFriend', yehuda); }); diff --git a/packages/ember-data/tests/integration/records/unload-test.js b/packages/ember-data/tests/integration/records/unload-test.js index 0e5008cfb39..2095819e0c9 100644 --- a/packages/ember-data/tests/integration/records/unload-test.js +++ b/packages/ember-data/tests/integration/records/unload-test.js @@ -204,7 +204,7 @@ test("unloading a record also clears the implicit inverse relationships", functi run(function() { env.store.find('group', 1).then(function(group) { equal(group.get('people.length'), 1, 'The inital length of people is correct'); - var person = env.store.getById('person', 1); + var person = env.store.peekRecord('person', 1); run(function() { person.unloadRecord(); }); diff --git a/packages/ember-data/tests/integration/serializers/rest-serializer-test.js b/packages/ember-data/tests/integration/serializers/rest-serializer-test.js index 9dc79a01c6f..0870b6514ae 100644 --- a/packages/ember-data/tests/integration/serializers/rest-serializer-test.js +++ b/packages/ember-data/tests/integration/serializers/rest-serializer-test.js @@ -188,9 +188,8 @@ if (!Ember.FEATURES.isEnabled('ds-new-serializer-api')) { }); }, /Encountered "home_planet" in payload, but no model was found for model name "garbage"/); - // assert non-warned records get pushed into store correctly - var superVillain = env.store.getById('super-villain', "1"); + var superVillain = env.store.peekRecord('super-villain', "1"); equal(get(superVillain, "firstName"), "Stanley"); // Serializers are singletons, so that"s why we use the store which @@ -210,7 +209,7 @@ if (!Ember.FEATURES.isEnabled('ds-new-serializer-api')) { noWarns(function() { run(function() { env.store.pushPayload('home-planet', jsonHash); - homePlanet = env.store.getById('home-planet', "1"); + homePlanet = env.store.peekRecord('home-planet', "1"); }); }); @@ -247,7 +246,7 @@ if (!Ember.FEATURES.isEnabled('ds-new-serializer-api')) { }, /Encountered "home_planets" in payload, but no model was found for model name "garbage"/); // assert non-warned records get pushed into store correctly - var superVillain = env.store.getById('super-villain', "1"); + var superVillain = env.store.peekRecord('super-villain', "1"); equal(get(superVillain, "firstName"), "Stanley"); // Serializers are singletons, so that"s why we use the store which @@ -267,7 +266,7 @@ if (!Ember.FEATURES.isEnabled('ds-new-serializer-api')) { noWarns(function() { run(function() { env.store.pushPayload('home-planet', jsonHash); - homePlanet = env.store.getById('home-planet', "1"); + homePlanet = env.store.peekRecord('home-planet', "1"); }); }); diff --git a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js index accac509a36..b1b6ab1be88 100644 --- a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js +++ b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js @@ -51,7 +51,7 @@ test("TEMPORARY: a record receives a didLoad callback once it materializes if it equal(didLoadCalled, 0, "didLoad was not called"); }); run(function() { - store.getById('person', 1); + store.peekRecord('person', 1); }); run(function() { equal(didLoadCalled, 1, "didLoad was called"); 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 65e5cdc2c44..463a987fd27 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 @@ -214,7 +214,7 @@ test("When finding a belongsTo relationship the inverse belongsTo relationship i }); run(function() { - store.getById('person', 1).get('occupation'); + store.peekRecord('person', 1).get('occupation'); }); }); 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 beb12f47d68..be32afe7331 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 @@ -374,15 +374,15 @@ test("possible to replace items in a relationship using setObjects w/ Ember Enum var tom, sylvain; run(function() { - tom = store.getById('person', '1'); - sylvain = store.getById('person', '2'); + tom = store.peekRecord('person', '1'); + sylvain = store.peekRecord('person', '2'); // Test that since sylvain.get('tags') instanceof DS.ManyArray, // addRecords on Relationship iterates correctly. tom.get('tags').setObjects(sylvain.get('tags')); }); equal(tom.get('tags.length'), 1); - equal(tom.get('tags.firstObject'), store.getById('tag', 2)); + equal(tom.get('tags.firstObject'), store.peekRecord('tag', 2)); }); test("it is possible to remove an item from a relationship", function() { 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 2a3892b5444..cdf7d17c8d5 100644 --- a/packages/ember-data/tests/unit/store/adapter-interop-test.js +++ b/packages/ember-data/tests/unit/store/adapter-interop-test.js @@ -446,7 +446,7 @@ test("initial values of belongsTo can be passed in as the third argument to find run(function() { store.find('person', 1, { preload: { friend: 2 } }).then(async(function() { - store.getById('person', 1).get('friend').then(async(function(friend) { + store.peekRecord('person', 1).get('friend').then(async(function(friend) { equal(friend.get('id'), '2', 'Preloaded belongsTo set'); })); })); diff --git a/packages/ember-data/tests/unit/store/get-by-id-test.js b/packages/ember-data/tests/unit/store/get-by-id-test.js deleted file mode 100644 index 440101867a8..00000000000 --- a/packages/ember-data/tests/unit/store/get-by-id-test.js +++ /dev/null @@ -1,35 +0,0 @@ -var env, store, Person; -var run = Ember.run; - -module("unit/store/getById - Store getById", { - setup: function() { - - Person = DS.Model.extend(); - Person.toString = function() { - return 'Person'; - }; - - env = setupStore({ - person: Person - }); - store = env.store; - }, - - teardown: function() { - Ember.run(store, 'destroy'); - } -}); - -test("getById should return the record if it is in the store ", function() { - - run(function() { - var person = store.push('person', { id: 1 }); - equal(person, store.getById('person', 1), 'getById only return the corresponding record in the store'); - }); -}); - -test("getById should return null if the record is not in the store ", function() { - run(function() { - equal(null, store.getById('person', 1), 'getById returns null if the corresponding record is not in the store'); - }); -}); diff --git a/packages/ember-data/tests/unit/store/peek-by-id-test.js b/packages/ember-data/tests/unit/store/peek-by-id-test.js new file mode 100644 index 00000000000..ad8d8db3122 --- /dev/null +++ b/packages/ember-data/tests/unit/store/peek-by-id-test.js @@ -0,0 +1,46 @@ +var env, store, Person; +var run = Ember.run; + +module("unit/store/peekRecord - Store peekRecord", { + setup: function() { + + Person = DS.Model.extend(); + Person.toString = function() { + return 'Person'; + }; + + env = setupStore({ + person: Person + }); + store = env.store; + }, + + teardown: function() { + Ember.run(store, 'destroy'); + } +}); + +test("peekRecord should return the record if it is in the store ", function() { + run(function() { + var person = store.push('person', { id: 1 }); + equal(person, store.peekRecord('person', 1), 'peekRecord only return the corresponding record in the store'); + }); +}); + +test("peekRecord should return null if the record is not in the store ", function() { + run(function() { + equal(null, store.peekRecord('person', 1), 'peekRecord returns null if the corresponding record is not in the store'); + }); +}); + +test("getById is deprecated", function() { + expectDeprecation( + function() { + run(function() { + store.push('person', { id: 1 }); + store.getById('person', 1); + }); + }, + 'Using store.getById() has been deprecated. Use store.peekRecord to get a record by a given type and ID without triggering a fetch.' + ); +}); diff --git a/packages/ember-data/tests/unit/store/push-test.js b/packages/ember-data/tests/unit/store/push-test.js index f1a30aa2469..e4f9bcf5387 100644 --- a/packages/ember-data/tests/unit/store/push-test.js +++ b/packages/ember-data/tests/unit/store/push-test.js @@ -250,7 +250,7 @@ test("Calling pushPayload allows pushing raw JSON", function () { }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); @@ -276,7 +276,7 @@ test("Calling pushPayload allows pushing singular payload properties", function }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); @@ -320,11 +320,11 @@ test("Calling pushPayload should use the type's serializer for normalizing", fun }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); - var person = store.getById('person', 2); + var person = store.peekRecord('person', 2); equal(person.get('firstName'), "Yehuda", "you can push raw JSON into the store"); }); @@ -376,11 +376,11 @@ test("Calling pushPayload without a type should use a model's serializer when no }); }); - var post = store.getById('post', 1); + var post = store.peekRecord('post', 1); equal(post.get('postTitle'), "Ember rocks", "you can push raw JSON into the store"); - var person = store.getById('person', 2); + var person = store.peekRecord('person', 2); equal(person.get('firstName'), "Yehuda", "you can push raw JSON into the store"); }); @@ -400,7 +400,7 @@ test("Calling pushPayload allows partial updates with raw JSON", function () { }); }); - person = store.getById('person', 1); + person = store.peekRecord('person', 1); equal(person.get('firstName'), "Robert", "you can push raw JSON into the store"); equal(person.get('lastName'), "Jackson", "you can push raw JSON into the store"); @@ -487,7 +487,7 @@ test('Calling push with a link containing the value null', function() { }); }); - var person = store.getById('person', 1); + var person = store.peekRecord('person', 1); equal(person.get('firstName'), "Tan", "you can use links that contain null as a value"); }); From 3f9b4b6c858a38139daa25c818e3d1f101bd3446 Mon Sep 17 00:00:00 2001 From: Eric Kelly Date: Thu, 4 Jun 2015 22:20:48 -0400 Subject: [PATCH 2/2] Rename & deprecate store.all for store.peekAll --- .../lib/system/debug/debug-adapter.js | 2 +- .../record-arrays/filtered-record-array.js | 2 +- .../lib/system/record-arrays/record-array.js | 8 +-- packages/ember-data/lib/system/store.js | 32 ++++++++- .../ember-data/lib/system/store/finders.js | 2 +- .../integration/adapter/find-all-test.js | 4 +- .../ember-data/tests/integration/all-test.js | 55 ---------------- .../tests/integration/peek-all-test.js | 66 +++++++++++++++++++ .../integration/record-array-manager-test.js | 4 +- .../records/collection-save-test.js | 8 +-- .../integration/records/delete-record-test.js | 4 +- .../tests/integration/records/unload-test.js | 18 ++--- .../relationships/has-many-test.js | 2 +- .../tests/integration/store-test.js | 8 +-- .../unit/model/lifecycle-callbacks-test.js | 2 +- .../tests/unit/model/rollback-test.js | 4 +- .../tests/unit/record-array-test.js | 12 ++-- .../tests/unit/store/adapter-interop-test.js | 8 +-- 18 files changed, 140 insertions(+), 101 deletions(-) delete mode 100644 packages/ember-data/tests/integration/all-test.js create mode 100644 packages/ember-data/tests/integration/peek-all-test.js diff --git a/packages/ember-data/lib/system/debug/debug-adapter.js b/packages/ember-data/lib/system/debug/debug-adapter.js index ee2ed753f23..ae5e01a022a 100644 --- a/packages/ember-data/lib/system/debug/debug-adapter.js +++ b/packages/ember-data/lib/system/debug/debug-adapter.js @@ -55,7 +55,7 @@ export default Ember.DataAdapter.extend({ } } assert("Cannot find model name. Please upgrade to Ember.js >= 1.13 for Ember Inspector support", !!modelName); - return this.get('store').all(modelName); + return this.get('store').peekAll(modelName); }, getRecordColumnValues: function(record) { diff --git a/packages/ember-data/lib/system/record-arrays/filtered-record-array.js b/packages/ember-data/lib/system/record-arrays/filtered-record-array.js index b03841d4731..9344294c2a7 100644 --- a/packages/ember-data/lib/system/record-arrays/filtered-record-array.js +++ b/packages/ember-data/lib/system/record-arrays/filtered-record-array.js @@ -24,7 +24,7 @@ export default RecordArray.extend({ Example ```javascript - var allPeople = store.all('person'); + var allPeople = store.peekAll('person'); allPeople.mapBy('name'); // ["Tom Dale", "Yehuda Katz", "Trek Glowacki"] var people = store.filter('person', function(person) { diff --git a/packages/ember-data/lib/system/record-arrays/record-array.js b/packages/ember-data/lib/system/record-arrays/record-array.js index 1ffbdde67e5..0a16d65f1ca 100644 --- a/packages/ember-data/lib/system/record-arrays/record-array.js +++ b/packages/ember-data/lib/system/record-arrays/record-array.js @@ -46,7 +46,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { Example ```javascript - var people = store.all('person'); + var people = store.peekAll('person'); people.get('isLoaded'); // true ``` @@ -60,7 +60,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { Example ```javascript - var people = store.all('person'); + var people = store.peekAll('person'); people.get('isUpdating'); // false people.update(); people.get('isUpdating'); // true @@ -101,7 +101,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { Example ```javascript - var people = store.all('person'); + var people = store.peekAll('person'); people.get('isUpdating'); // false people.update(); people.get('isUpdating'); // true @@ -152,7 +152,7 @@ export default Ember.ArrayProxy.extend(Ember.Evented, { Example ```javascript - var messages = store.all('message'); + var messages = store.peekAll('message'); messages.forEach(function(message) { message.set('hasBeenSeen', true); }); diff --git a/packages/ember-data/lib/system/store.js b/packages/ember-data/lib/system/store.js index f14081beb5e..4fef2f0f077 100644 --- a/packages/ember-data/lib/system/store.js +++ b/packages/ember-data/lib/system/store.js @@ -203,7 +203,7 @@ if (!Service) { Note: When creating a new record using any of the above methods Ember Data will update `DS.RecordArray`s such as those returned by - `store#all()`, `store#findAll()` or `store#filter()`. This means any + `store#peekAll()`, `store#findAll()` or `store#filter()`. This means any data bindings or computed properties that depend on the RecordArray will automatically be synced to include the new or updated record values. @@ -1049,7 +1049,7 @@ Store = Service.extend({ Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); - return this._fetchAll(typeClass, this.all(modelName)); + return this._fetchAll(typeClass, this.peekAll(modelName)); }, /** @@ -1105,6 +1105,34 @@ Store = Service.extend({ @return {DS.RecordArray} */ all: function(modelName) { + Ember.deprecate('Using store.all() has been deprecated. Use store.peekAll() to get all records by a given type without triggering a fetch.'); + return this.peekAll(modelName); + }, + + /** + This method returns a filtered array that contains all of the + known records for a given type in the store. + + Note that because it's just a filter, the result will contain any + locally created records of the type, however, it will not make a + request to the backend to retrieve additional records. If you + would like to request all the records from the backend please use + [store.find](#method_find). + + Also note that multiple calls to `peekAll` for a given type will always + return the same `RecordArray`. + + Example + + ```javascript + var localPosts = store.peekAll('post'); + ``` + + @method peekAll + @param {String} modelName + @return {DS.RecordArray} + */ + peekAll: function(modelName) { Ember.assert('Passing classes to store methods has been removed. Please pass a dasherized string instead of '+ Ember.inspect(modelName), typeof modelName === 'string'); var typeClass = this.modelFor(modelName); diff --git a/packages/ember-data/lib/system/store/finders.js b/packages/ember-data/lib/system/store/finders.js index ed43cb7643a..2d156f476b4 100644 --- a/packages/ember-data/lib/system/store/finders.js +++ b/packages/ember-data/lib/system/store/finders.js @@ -135,7 +135,7 @@ export function _findAll(adapter, store, typeClass, sinceToken) { }); store.didUpdateAll(typeClass); - return store.all(modelName); + return store.peekAll(modelName); }, null, "DS: Extract payload of findAll " + typeClass); } diff --git a/packages/ember-data/tests/integration/adapter/find-all-test.js b/packages/ember-data/tests/integration/adapter/find-all-test.js index 846dcc58cd9..958b11860f1 100644 --- a/packages/ember-data/tests/integration/adapter/find-all-test.js +++ b/packages/ember-data/tests/integration/adapter/find-all-test.js @@ -103,7 +103,7 @@ test("When all records for a type are requested, records that are already loaded store.createRecord('person', { name: "Alex MacCaw" }); }); - allRecords = store.all('person'); + allRecords = store.peekAll('person'); equal(get(allRecords, 'length'), 2, "the record array's length is 2"); equal(allRecords.objectAt(0).get('name'), "Jeremy Ashkenas", "the first item in the record array is Jeremy Ashkenas"); @@ -118,7 +118,7 @@ test("When all records for a type are requested, records that are created on the person: Person }); - allRecords = store.all('person'); + allRecords = store.peekAll('person'); equal(get(allRecords, 'length'), 0, "precond - the record array's length is zero before any records are loaded"); diff --git a/packages/ember-data/tests/integration/all-test.js b/packages/ember-data/tests/integration/all-test.js deleted file mode 100644 index 31dbdc9207a..00000000000 --- a/packages/ember-data/tests/integration/all-test.js +++ /dev/null @@ -1,55 +0,0 @@ -var get = Ember.get; -var run = Ember.run; - -var Person, store, array, moreArray; - -module("integration/all - DS.Store#all()", { - setup: function() { - array = [{ id: 1, name: "Scumbag Dale" }, { id: 2, name: "Scumbag Katz" }]; - moreArray = [{ id: 3, name: "Scumbag Bryn" }]; - Person = DS.Model.extend({ name: DS.attr('string') }); - - store = createStore({ person: Person }); - }, - teardown: function() { - run(store, 'destroy'); - Person = null; - array = null; - } -}); - -test("store.all('person') should return all records and should update with new ones", function() { - run(function() { - store.pushMany('person', array); - }); - - var all = store.all('person'); - equal(get(all, 'length'), 2); - - run(function() { - store.pushMany('person', moreArray); - }); - - equal(get(all, 'length'), 3); -}); - -test("Calling store.all() multiple times should update immediately inside the runloop", function() { - expect(3); - - Ember.run(function() { - equal(get(store.all('person'), 'length'), 0, 'should initially be empty'); - store.createRecord('person', { name: "Tomster" }); - equal(get(store.all('person'), 'length'), 1, 'should contain one person'); - store.push('person', { id: 1, name: "Tomster's friend" }); - equal(get(store.all('person'), 'length'), 2, 'should contain two people'); - }); -}); - -test("Calling store.all() after creating a record should return correct data", function() { - expect(1); - - Ember.run(function() { - store.createRecord('person', { name: "Tomster" }); - equal(get(store.all('person'), 'length'), 1, 'should contain one person'); - }); -}); diff --git a/packages/ember-data/tests/integration/peek-all-test.js b/packages/ember-data/tests/integration/peek-all-test.js new file mode 100644 index 00000000000..51788dc7df5 --- /dev/null +++ b/packages/ember-data/tests/integration/peek-all-test.js @@ -0,0 +1,66 @@ +var get = Ember.get; +var run = Ember.run; + +var Person, store, array, moreArray; + +module("integration/peek_all - DS.Store#peekAll()", { + setup: function() { + array = [{ id: 1, name: "Scumbag Dale" }, { id: 2, name: "Scumbag Katz" }]; + moreArray = [{ id: 3, name: "Scumbag Bryn" }]; + Person = DS.Model.extend({ name: DS.attr('string') }); + + store = createStore({ person: Person }); + }, + teardown: function() { + run(store, 'destroy'); + Person = null; + array = null; + } +}); + +test("store.peekAll('person') should return all records and should update with new ones", function() { + run(function() { + store.pushMany('person', array); + }); + + var all = store.peekAll('person'); + equal(get(all, 'length'), 2); + + run(function() { + store.pushMany('person', moreArray); + }); + + equal(get(all, 'length'), 3); +}); + +test("Calling store.peekAll() multiple times should update immediately inside the runloop", function() { + expect(3); + + Ember.run(function() { + equal(get(store.peekAll('person'), 'length'), 0, 'should initially be empty'); + store.createRecord('person', { name: "Tomster" }); + equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); + store.push('person', { id: 1, name: "Tomster's friend" }); + equal(get(store.peekAll('person'), 'length'), 2, 'should contain two people'); + }); +}); + +test("Calling store.peekAll() after creating a record should return correct data", function() { + expect(1); + + Ember.run(function() { + store.createRecord('person', { name: "Tomster" }); + equal(get(store.peekAll('person'), 'length'), 1, 'should contain one person'); + }); +}); + +test("store.all() is deprecated", function() { + expectDeprecation( + function() { + run(function() { + store.all('person'); + }); + }, + 'Using store.all() has been deprecated. Use store.peekAll() to get all records by a given type without triggering a fetch.' + ); +}); diff --git a/packages/ember-data/tests/integration/record-array-manager-test.js b/packages/ember-data/tests/integration/record-array-manager-test.js index 66d6d80f619..9893609404a 100644 --- a/packages/ember-data/tests/integration/record-array-manager-test.js +++ b/packages/ember-data/tests/integration/record-array-manager-test.js @@ -105,13 +105,13 @@ test("destroying the store correctly cleans everything up", function() { equal(adapterPopulatedSummary.called.length, 1); }); -test("Should not filter a store.all() array when a record property is changed", function() { +test("Should not filter a store.peekAll() array when a record property is changed", function() { var car; var populateLiveRecordArray = tap(store.recordArrayManager, 'populateLiveRecordArray'); var updateFilterRecordArray = tap(store.recordArrayManager, 'updateFilterRecordArray'); - store.all('car'); + store.peekAll('car'); run(function() { car = store.push('car', { diff --git a/packages/ember-data/tests/integration/records/collection-save-test.js b/packages/ember-data/tests/integration/records/collection-save-test.js index e64f38091fc..a18282c3508 100644 --- a/packages/ember-data/tests/integration/records/collection-save-test.js +++ b/packages/ember-data/tests/integration/records/collection-save-test.js @@ -24,7 +24,7 @@ test("Collection will resolve save on success", function() { env.store.createRecord('post', { title: 'World' }); }); - var posts = env.store.all('post'); + var posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { return Ember.RSVP.resolve({ id: 123 }); @@ -43,7 +43,7 @@ test("Collection will reject save on error", function() { env.store.createRecord('post', { title: 'World' }); }); - var posts = env.store.all('post'); + var posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { return Ember.RSVP.reject(); @@ -62,7 +62,7 @@ test("Retry is allowed in a failure handler", function() { env.store.createRecord('post', { title: 'World' }); }); - var posts = env.store.all('post'); + var posts = env.store.peekAll('post'); var count = 0; @@ -94,7 +94,7 @@ test("Collection will reject save on invalid", function() { env.store.createRecord('post', { title: 'World' }); }); - var posts = env.store.all('post'); + var posts = env.store.peekAll('post'); env.adapter.createRecord = function(store, type, snapshot) { return Ember.RSVP.reject({ title: 'invalid' }); diff --git a/packages/ember-data/tests/integration/records/delete-record-test.js b/packages/ember-data/tests/integration/records/delete-record-test.js index ad31e24beb6..66bf4cd4434 100644 --- a/packages/ember-data/tests/integration/records/delete-record-test.js +++ b/packages/ember-data/tests/integration/records/delete-record-test.js @@ -28,7 +28,7 @@ test("records can be deleted during record array enumeration", function () { adam = env.store.push('person', { id: 1, name: "Adam Sunderland" }); dave = env.store.push('person', { id: 2, name: "Dave Sunderland" }); }); - var all = env.store.all('person'); + var all = env.store.peekAll('person'); // pre-condition equal(all.get('length'), 2, 'expected 2 records'); @@ -49,7 +49,7 @@ test("when deleted records are rolled back, they are still in their previous rec jaime = env.store.push('person', { id: 1, name: "Jaime Lannister" }); cersei = env.store.push('person', { id: 2, name: "Cersei Lannister" }); }); - var all = env.store.all('person'); + var all = env.store.peekAll('person'); var filtered; run(function() { filtered = env.store.filter('person', function () { diff --git a/packages/ember-data/tests/integration/records/unload-test.js b/packages/ember-data/tests/integration/records/unload-test.js index 2095819e0c9..e7b1de0f238 100644 --- a/packages/ember-data/tests/integration/records/unload-test.js +++ b/packages/ember-data/tests/integration/records/unload-test.js @@ -51,7 +51,7 @@ test("can unload a single record", function () { adam.unloadRecord(); }); - equal(env.store.all('person').get('length'), 0); + equal(env.store.peekAll('person').get('length'), 0); }); test("can unload all records for a given type", function () { @@ -74,8 +74,8 @@ test("can unload all records for a given type", function () { env.store.unloadAll('person'); }); - equal(env.store.all('person').get('length'), 0); - equal(env.store.all('car').get('length'), 1); + equal(env.store.peekAll('person').get('length'), 0); + equal(env.store.peekAll('car').get('length'), 1); }); test("can unload all records", function () { @@ -98,8 +98,8 @@ test("can unload all records", function () { env.store.unloadAll(); }); - equal(env.store.all('person').get('length'), 0); - equal(env.store.all('car').get('length'), 0); + equal(env.store.peekAll('person').get('length'), 0); + equal(env.store.peekAll('car').get('length'), 0); }); test("Unloading all records for a given type clears saved meta data.", function () { @@ -128,20 +128,20 @@ test("removes findAllCache after unloading all records", function () { }); Ember.run(function() { - env.store.all('person'); + env.store.peekAll('person'); env.store.unloadAll('person'); }); - equal(env.store.all('person').get('length'), 0); + equal(env.store.peekAll('person').get('length'), 0); }); -test("unloading all records also updates record array from all()", function() { +test("unloading all records also updates record array from peekAll()", function() { var adam, bob; run(function() { adam = env.store.push('person', { id: 1, name: "Adam Sunderland" }); bob = env.store.push('person', { id: 2, name: "Bob Bobson" }); }); - var all = env.store.all('person'); + var all = env.store.peekAll('person'); equal(all.get('length'), 2); 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 f9cf9b97c70..2339ed9a438 100644 --- a/packages/ember-data/tests/integration/relationships/has-many-test.js +++ b/packages/ember-data/tests/integration/relationships/has-many-test.js @@ -1219,7 +1219,7 @@ test("Relationship.clear removes all records correctly", function() { run(function() { post._internalModel._relationships.get('comments').clear(); - var comments = Ember.A(env.store.all('comment')); + var comments = Ember.A(env.store.peekAll('comment')); deepEqual(comments.mapBy('post'), [null, null, null]); }); diff --git a/packages/ember-data/tests/integration/store-test.js b/packages/ember-data/tests/integration/store-test.js index 53c2d6623b3..2977ad108d2 100644 --- a/packages/ember-data/tests/integration/store-test.js +++ b/packages/ember-data/tests/integration/store-test.js @@ -324,7 +324,7 @@ test("Using store#findAll with no records triggers a query", function() { }] }); - var cars = store.all('car'); + var cars = store.peekAll('car'); ok(!cars.get('length'), 'There is no cars in the store'); run(function() { @@ -358,7 +358,7 @@ test("Using store#findAll with existing records performs a query, updating exist }] }); - var cars = store.all('car'); + var cars = store.peekAll('car'); equal(cars.get('length'), 1, 'There is one car in the store'); run(function() { @@ -386,7 +386,7 @@ test("store#findAll should return all known records even if they are not in the }] }); - var cars = store.all('car'); + var cars = store.peekAll('car'); equal(cars.get('length'), 2, 'There is two cars in the store'); run(function() { @@ -395,7 +395,7 @@ test("store#findAll should return all known records even if they are not in the var mini = cars.findBy('id', '1'); equal(mini.get('model'), 'New Mini', 'Existing records have been updated'); - var carsInStore = store.all('car'); + var carsInStore = store.peekAll('car'); equal(carsInStore.get('length'), 2, 'There is 2 cars in the store'); }); }); diff --git a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js index b1b6ab1be88..b8c3f08ab30 100644 --- a/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js +++ b/packages/ember-data/tests/unit/model/lifecycle-callbacks-test.js @@ -306,5 +306,5 @@ test("an ID of 0 is allowed", function() { store.push('person', { id: 0, name: "Tom Dale" }); }); - equal(store.all('person').objectAt(0).get('name'), "Tom Dale", "found record with id 0"); + equal(store.peekAll('person').objectAt(0).get('name'), "Tom Dale", "found record with id 0"); }); diff --git a/packages/ember-data/tests/unit/model/rollback-test.js b/packages/ember-data/tests/unit/model/rollback-test.js index 6db9b6eb832..0095245e347 100644 --- a/packages/ember-data/tests/unit/model/rollback-test.js +++ b/packages/ember-data/tests/unit/model/rollback-test.js @@ -118,7 +118,7 @@ test("a deleted record can be rollbacked if it fails to save, record arrays are run(function() { person = store.push('person', { id: 1, firstName: "Tom", lastName: "Dale" }); - people = store.all('person'); + people = store.peekAll('person'); }); run(function() { @@ -209,7 +209,7 @@ test("deleted record can be rollbacked", function() { run(function() { person = store.push('person', { id: 1 }); - people = store.all('person'); + people = store.peekAll('person'); person.deleteRecord(); }); diff --git a/packages/ember-data/tests/unit/record-array-test.js b/packages/ember-data/tests/unit/record-array-test.js index fdd61e72d6c..05f3fe5c1de 100644 --- a/packages/ember-data/tests/unit/record-array-test.js +++ b/packages/ember-data/tests/unit/record-array-test.js @@ -37,7 +37,7 @@ test("acts as a live query", function() { var store = createStore({ person: Person }); - var recordArray = store.all('person'); + var recordArray = store.peekAll('person'); run(function() { store.push('person', { id: 1, name: 'wycats' }); }); @@ -60,7 +60,7 @@ test("stops updating when destroyed", function() { // is on the release branch var emptyLength = Ember.meta(store).descs ? undefined : 0; - var recordArray = store.all('person'); + var recordArray = store.peekAll('person'); run(function() { store.push('person', { id: 1, name: 'wycats' }); }); @@ -188,7 +188,7 @@ test("a newly created record is removed from a record array when it is deleted", var store = createStore({ person: Person }); - var recordArray = store.all('person'); + var recordArray = store.peekAll('person'); var scumbag; run(function() { @@ -231,7 +231,7 @@ test("a record array returns undefined when asking for a member outside of its c store.pushMany('person', array); }); - var recordArray = store.all('person'); + var recordArray = store.peekAll('person'); strictEqual(recordArray.objectAt(20), undefined, "objects outside of the range just return undefined"); }); @@ -245,7 +245,7 @@ test("a record array should be able to be enumerated in any order", function() { store.pushMany('person', array); }); - var recordArray = store.all('person'); + var recordArray = store.peekAll('person'); equal(get(recordArray.objectAt(2), 'id'), 3, "should retrieve correct record at index 2"); equal(get(recordArray.objectAt(1), 'id'), 2, "should retrieve correct record at index 1"); @@ -278,7 +278,7 @@ test("a record array should return a promise when updating", function() { return Ember.RSVP.resolve(array); }; - recordArray = store.all('person'); + recordArray = store.peekAll('person'); run(function() { promise = recordArray.update(); }); 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 cdf7d17c8d5..244befa8091 100644 --- a/packages/ember-data/tests/unit/store/adapter-interop-test.js +++ b/packages/ember-data/tests/unit/store/adapter-interop-test.js @@ -255,7 +255,7 @@ test("Find with query calls the correct extract", function() { equal(callCount, 1, 'extractFindQuery was called'); }); -test("all(type) returns a record array of all records of a specific type", function() { +test("peekAll(type) returns a record array of all records of a specific type", function() { var Person = DS.Model.extend({ name: DS.attr('string') }); @@ -268,7 +268,7 @@ test("all(type) returns a record array of all records of a specific type", funct store.push('person', { id: 1, name: "Tom Dale" }); }); - var results = store.all('person'); + var results = store.peekAll('person'); equal(get(results, 'length'), 1, "record array should have the original object"); equal(get(results.objectAt(0), 'name'), "Tom Dale", "record has the correct information"); @@ -278,7 +278,7 @@ test("all(type) returns a record array of all records of a specific type", funct equal(get(results, 'length'), 2, "record array should have the new object"); equal(get(results.objectAt(1), 'name'), "Yehuda Katz", "record has the correct information"); - strictEqual(results, store.all('person'), "subsequent calls to all return the same recordArray)"); + strictEqual(results, store.peekAll('person'), "subsequent calls to peekAll return the same recordArray)"); }); test("a new record of a particular type is created via store.createRecord(type)", function() { @@ -527,7 +527,7 @@ test("records should have their ids updated when the adapter returns the id data person: Person }); - var people = store.all('person'); + var people = store.peekAll('person'); var tom, yehuda; run(function() {