Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls to store.find with store.findRecord #4039

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/-private/system/coerce-id.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Used by the store to normalize IDs entering the store. Despite the fact
// that developers may provide IDs as numbers (e.g., `store.find(Person, 1)`),
// that developers may provide IDs as numbers (e.g., `store.findRecord('person', 1)`),
// it is important that internally we use strings, since IDs may be serialized
// and lose type information. For example, Ember's router may put a record's
// ID into the URL, and if we later try to deserialize that URL and find the
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/many-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export default Ember.Object.extend(Ember.MutableArray, Ember.Evented, {
Example
```javascript
store.find('inbox', 1).then(function(inbox) {
store.findRecord('inbox', 1).then(function(inbox) {
inbox.get('messages').then(function(messages) {
messages.forEach(function(message) {
message.set('isRead', true);
Expand Down
2 changes: 1 addition & 1 deletion addon/-private/system/model/internal-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ InternalModel.prototype = {
came back from the server, except the user obtained them out of band and is informing
the store of their existence. The most common use case is for supporting client side
nested URLs, such as `/posts/1/comments/2` so the user can do
`store.find('comment', 2, {post:1})` without having to fetch the post.
`store.findRecord('comment', 2, { preload: { post: 1 } })` without having to fetch the post.
Preloaded data can be attributes and relationships passed in either as IDs or as actual
models.
Expand Down
8 changes: 4 additions & 4 deletions addon/-private/system/model/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
var record = store.createRecord('model');
record.get('isLoaded'); // true
store.find('model', 1).then(function(model) {
store.findRecord('model', 1).then(function(model) {
model.get('isLoaded'); // true
});
```
Expand All @@ -105,7 +105,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
var record = store.createRecord('model');
record.get('hasDirtyAttributes'); // true
store.find('model', 1).then(function(model) {
store.findRecord('model', 1).then(function(model) {
model.get('hasDirtyAttributes'); // false
model.set('foo', 'some value');
model.get('hasDirtyAttributes'); // true
Expand Down Expand Up @@ -284,7 +284,7 @@ var Model = Ember.Object.extend(Ember.Evented, {
var record = store.createRecord('model');
record.get('id'); // null
store.find('model', 1).then(function(model) {
store.findRecord('model', 1).then(function(model) {
model.get('id'); // '1'
});
```
Expand Down Expand Up @@ -885,7 +885,7 @@ if (isEnabled("ds-references")) {
var link = userRef.link();
}
// load user (via store.find or store.findBelongsTo)
// load user (via store.findRecord or store.findBelongsTo)
userRef.load().then(...)
// or trigger a reload
Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -1227,14 +1227,14 @@ Store = Service.extend({

/**
This method returns if a certain record is already loaded
in the store. Use this function to know beforehand if a find()
in the store. Use this function to know beforehand if a findRecord()
will result in a request or that it will be a cache hit.

Example

```javascript
store.recordIsLoaded('post', 1); // false
store.find('post', 1).then(function() {
store.findRecord('post', 1).then(function() {
store.recordIsLoaded('post', 1); // true
});
```
Expand Down
4 changes: 2 additions & 2 deletions addon/-private/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ export function _find(adapter, store, typeClass, id, internalModel, options) {
var snapshot = internalModel.createSnapshot(options);
var promise = adapter.findRecord(store, typeClass, id, snapshot);
var serializer = serializerForAdapter(store, adapter, internalModel.type.modelName);
var label = "DS: Handle Adapter#find of " + typeClass + " with id: " + id;
var label = "DS: Handle Adapter#findRecord of " + typeClass + " with id: " + id;

promise = Promise.resolve(promise, label);
promise = _guard(promise, _bind(_objectIsAlive, store));

return promise.then(function(adapterPayload) {
assert("You made a `find` request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload));
assert("You made a `findRecord` request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", payloadIsNotBlank(adapterPayload));
return store._adapterRun(function() {
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, 'findRecord');
assert('Ember Data expected the primary data returned from a `findRecord` response to be an object but instead it found an array.', !Array.isArray(payload.data));
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/adapter/find-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test("When a single record is requested, the adapter's find method should be cal
});
});

test("When a single record is requested multiple times, all .find() calls are resolved after the promise is resolved", (assert) => {
test("When a single record is requested multiple times, all .findRecord() calls are resolved after the promise is resolved", (assert) => {
var deferred = Ember.RSVP.defer();

env.registry.register('adapter:person', DS.Adapter.extend({
Expand Down Expand Up @@ -103,7 +103,7 @@ test("When a single record is requested multiple times, all .find() calls are re
run(() => deferred.resolve({ id: 1, name: "Braaaahm Dale" }));
});

test("When a single record is requested, and the promise is rejected, .find() is rejected.", (assert) => {
test("When a single record is requested, and the promise is rejected, .findRecord() is rejected.", (assert) => {
env.registry.register('adapter:person', DS.Adapter.extend({
findRecord: () => reject()
}));
Expand Down Expand Up @@ -136,7 +136,7 @@ test('When a single record is requested, and the payload is blank', (assert) =>
}));

assert.expectAssertion(() => {
run(() => store.find('person', 'the-id'));
run(() => store.findRecord('person', 'the-id'));
}, /the adapter's response did not have any data/);
});

Expand Down
22 changes: 11 additions & 11 deletions tests/integration/adapter/json-api-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ test('find a single record', function(assert) {
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -251,7 +251,7 @@ test('find a single record with belongsTo link as object { related }', function(
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -296,7 +296,7 @@ test('find a single record with belongsTo link as object { data }', function(ass
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -342,7 +342,7 @@ test('find a single record with belongsTo link as object { data } (polymorphic)'
}]);

run(function() {
store.find('user', 1).then(function(user) {
store.findRecord('user', 1).then(function(user) {
assert.equal(passedUrl[0], '/users/1');

assert.equal(user.get('id'), '1');
Expand Down Expand Up @@ -388,7 +388,7 @@ test('find a single record with sideloaded belongsTo link as object { data }', f

run(function() {

store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -440,7 +440,7 @@ test('find a single record with hasMany link as object { related }', function(as
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -495,7 +495,7 @@ test('find a single record with hasMany link as object { data }', function(asser
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -552,7 +552,7 @@ test('find a single record with hasMany link as object { data } (polymorphic)',
}]);

run(function() {
store.find('user', 1).then(function(user) {
store.findRecord('user', 1).then(function(user) {
assert.equal(passedUrl[0], '/users/1');

assert.equal(user.get('id'), '1');
Expand Down Expand Up @@ -606,7 +606,7 @@ test('find a single record with sideloaded hasMany link as object { data }', fun
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');

assert.equal(post.get('id'), '1');
Expand Down Expand Up @@ -659,7 +659,7 @@ test('find a single record with sideloaded hasMany link as object { data } (poly
}]);

run(function() {
store.find('user', 1).then(function(user) {
store.findRecord('user', 1).then(function(user) {
assert.equal(passedUrl[0], '/users/1');

assert.equal(user.get('id'), '1');
Expand Down Expand Up @@ -906,7 +906,7 @@ test('fetching a belongsTo relationship link that returns null', function(assert
}]);

run(function() {
store.find('post', 1).then(function(post) {
store.findRecord('post', 1).then(function(post) {
assert.equal(passedUrl[0], '/posts/1');
return post.get('author');

Expand Down
14 changes: 7 additions & 7 deletions tests/integration/adapter/record-persistence-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ test("After a created record has been assigned an ID, finding a record by that I
tom.save();
});

assert.asyncEqual(tom, env.store.find('person', 1), "the retrieved record is the same as the created record");
assert.asyncEqual(tom, env.store.findRecord('person', 1), "the retrieved record is the same as the created record");
});

test("when a store is committed, the adapter's `commit` method should be called with records that have been deleted.", function(assert) {
Expand All @@ -125,7 +125,7 @@ test("when a store is committed, the adapter's `commit` method should be called
}
});
});
env.store.find('person', 1).then(assert.wait(function(person) {
env.store.findRecord('person', 1).then(assert.wait(function(person) {
tom = person;
tom.deleteRecord();
return tom.save();
Expand Down Expand Up @@ -155,7 +155,7 @@ test("An adapter can notify the store that records were updated by calling `didS
});
});

all([env.store.find('person', 1), env.store.find('person', 2)])
all([env.store.findRecord('person', 1), env.store.findRecord('person', 2)])
.then(assert.wait(function(array) {
tom = array[0];
yehuda = array[1];
Expand Down Expand Up @@ -203,7 +203,7 @@ test("An adapter can notify the store that records were updated and provide new
});
});

hash({ tom: env.store.find('person', 1), yehuda: env.store.find('person', 2) }).then(assert.wait(function(people) {
hash({ tom: env.store.findRecord('person', 1), yehuda: env.store.findRecord('person', 2) }).then(assert.wait(function(people) {
people.tom.set('name', "Draaaaaahm Dale");
people.yehuda.set('name', "Goy Katz");

Expand Down Expand Up @@ -233,7 +233,7 @@ test("An adapter can notify the store that a record was updated by calling `didS
});
});

hash({ tom: store.find('person', 1), yehuda: store.find('person', 2) }).then(assert.wait(function(people) {
hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }).then(assert.wait(function(people) {
people.tom.set('name', "Tom Dale");
people.yehuda.set('name', "Yehuda Katz");

Expand Down Expand Up @@ -274,7 +274,7 @@ test("An adapter can notify the store that a record was updated and provide new
});
});

hash({ tom: store.find('person', 1), yehuda: store.find('person', 2) }).then(assert.wait(function(people) {
hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }).then(assert.wait(function(people) {
people.tom.set('name', "Draaaaaahm Dale");
people.yehuda.set('name', "Goy Katz");

Expand Down Expand Up @@ -311,7 +311,7 @@ test("An adapter can notify the store that records were deleted by calling `didS
});
});

hash({ tom: store.find('person', 1), yehuda: store.find('person', 2) }).then(assert.wait(function(people) {
hash({ tom: store.findRecord('person', 1), yehuda: store.findRecord('person', 2) }).then(assert.wait(function(people) {
people.tom.deleteRecord();
people.yehuda.deleteRecord();

Expand Down
20 changes: 10 additions & 10 deletions tests/integration/adapter/rest-adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ test("findRecord - passes buildURL a requestType", function(assert) {
}));
});

test("find - basic payload (with legacy singular name)", function(assert) {
test("findRecord - basic payload (with legacy singular name)", function(assert) {
ajaxResponse({ post: { id: 1, name: "Rails is omakase" } });

run(store, 'findRecord', 'post', 1).then(assert.wait(function(post) {
Expand Down Expand Up @@ -2069,7 +2069,7 @@ test('normalizeKey - to set up _ids and _id', function(assert) {
});

run(function() {
store.find('post', 1).then(assert.wait(function(post) {
store.findRecord('post', 1).then(assert.wait(function(post) {
assert.equal(post.get('authorName'), "@d2h");
assert.equal(post.get('author.name'), "D2H");
assert.deepEqual(post.get('comments').mapBy('body'), ["Rails is unagi", "What is omakase?"]);
Expand Down Expand Up @@ -2163,7 +2163,7 @@ test('groupRecordsForFindMany groups calls for small ids', function(assert) {
adapter.coalesceFindRequests = true;

adapter.findRecord = function(store, type, id, snapshot) {
assert.ok(false, "find should not be called - we expect 1 call to findMany for a100 and b100");
assert.ok(false, "findRecord should not be called - we expect 1 call to findMany for a100 and b100");
return Ember.RSVP.reject();
};

Expand Down Expand Up @@ -2204,7 +2204,7 @@ test("calls adapter.handleResponse with the jqXHR and json", function(assert) {

try {
run(function() {
store.find('post', '1');
store.findRecord('post', '1');
});
} finally {
Ember.$.ajax = originalAjax;
Expand Down Expand Up @@ -2238,7 +2238,7 @@ test('calls handleResponse with jqXHR, jqXHR.responseText, and requestData', fun

try {
run(function() {
store.find('post', '1').catch(function(err) {
store.findRecord('post', '1').catch(function(err) {
assert.ok(err, 'promise rejected');
});
});
Expand Down Expand Up @@ -2267,7 +2267,7 @@ test("rejects promise if DS.AdapterError is returned from adapter.handleResponse
};

Ember.run(function() {
store.find('post', '1').then(null, function(reason) {
store.findRecord('post', '1').then(null, function(reason) {
assert.ok(true, 'promise should be rejected');
assert.ok(reason instanceof DS.AdapterError, 'reason should be an instance of DS.AdapterError');
});
Expand Down Expand Up @@ -2297,7 +2297,7 @@ test('on error appends errorThrown for sanity', function(assert) {

try {
run(function() {
store.find('post', '1').catch(function(err) {
store.findRecord('post', '1').catch(function(err) {
assert.equal(err, errorThrown);
assert.ok(err, 'promise rejected');
});
Expand Down Expand Up @@ -2325,7 +2325,7 @@ test('on error wraps the error string in an DS.AdapterError object', function(as

try {
run(function() {
store.find('post', '1').catch(function(err) {
store.findRecord('post', '1').catch(function(err) {
assert.equal(err.errors[0].detail, errorThrown);
assert.ok(err, 'promise rejected');
});
Expand All @@ -2351,7 +2351,7 @@ test('error handling includes a detailed message from the server', (assert) => {

try {
run(function() {
store.find('post', '1').catch(function(err) {
store.findRecord('post', '1').catch(function(err) {
assert.equal(err.message, "Ember Data Request GET /posts/1 returned a 500\nPayload (text/plain)\nAn error message, perhaps generated from a backend server!");
assert.ok(err, 'promise rejected');
});
Expand All @@ -2378,7 +2378,7 @@ test('error handling with a very long HTML-formatted payload truncates the frien

try {
run(function() {
store.find('post', '1').catch(function(err) {
store.findRecord('post', '1').catch(function(err) {
assert.equal(err.message, "Ember Data Request GET /posts/1 returned a 500\nPayload (text/html)\n[Omitted Lengthy HTML]");
assert.ok(err, 'promise rejected');
});
Expand Down
Loading