Skip to content

Commit

Permalink
Deprecate store.fetchAll in favor of store.findAll
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroicEric committed Jun 6, 2015
1 parent 1a57000 commit 061ca78
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
9 changes: 5 additions & 4 deletions packages/ember-data/lib/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,8 @@ Store = Service.extend({
*/
fetchAll: 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);

return this._fetchAll(typeClass, this.all(modelName));
Ember.deprecate('Using store.fetchAll(type) has been deprecated. Use store.findAll(type) to retrieve all records for a given type.');
return this.findAll(modelName);
},

/**
Expand Down Expand Up @@ -1003,7 +1002,9 @@ Store = Service.extend({
*/
findAll: 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');
return this.fetchAll(modelName);
var typeClass = this.modelFor(modelName);

return this._fetchAll(typeClass, this.all(modelName));
},

/**
Expand Down
29 changes: 22 additions & 7 deletions packages/ember-data/tests/integration/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,28 @@ test("Using store#fetchById on existing record reloads it", function() {
});
});

module("integration/store - fetchAll", {
module("integration/store - findAll", {
setup: function() {
initializeStore(DS.RESTAdapter.extend());
}
});

test("Using store#fetchAll with no records triggers a query", function() {
test("store#fetchAll() is deprecated", function() {
ajaxResponse({
cars: []
});

expectDeprecation(
function() {
run(function() {
store.fetchAll('car');
});
},
'Using store.fetchAll(type) has been deprecated. Use store.findAll(type) to retrieve all records for a given type.'
);
});

test("Using store#findAll with no records triggers a query", function() {
expect(2);

ajaxResponse({
Expand All @@ -295,13 +310,13 @@ test("Using store#fetchAll with no records triggers a query", function() {
ok(!cars.get('length'), 'There is no cars in the store');

run(function() {
store.fetchAll('car').then(function(cars) {
store.findAll('car').then(function(cars) {
equal(cars.get('length'), 2, 'Two car were fetched');
});
});
});

test("Using store#fetchAll with existing records performs a query, updating existing records and returning new ones", function() {
test("Using store#findAll with existing records performs a query, updating existing records and returning new ones", function() {
expect(3);

run(function() {
Expand Down Expand Up @@ -329,15 +344,15 @@ test("Using store#fetchAll with existing records performs a query, updating exis
equal(cars.get('length'), 1, 'There is one car in the store');

run(function() {
store.fetchAll('car').then(function(cars) {
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');
});
});
});

test("store#fetchAll should return all known records even if they are not in the adapter response", function() {
test("store#findAll should return all known records even if they are not in the adapter response", function() {
expect(4);

run(function() {
Expand All @@ -357,7 +372,7 @@ test("store#fetchAll should return all known records even if they are not in the
equal(cars.get('length'), 2, 'There is two cars in the store');

run(function() {
store.fetchAll('car').then(function(cars) {
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');
Expand Down

0 comments on commit 061ca78

Please sign in to comment.