-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
isLoading true
after failed response from server
#3013
Comments
Hi, |
Is this such a failing test for this scenario? var get = Ember.get;
var hasMany = DS.hasMany;
var Post, Comment, env;
var run = Ember.run;
module("integration/load - Loading Records", {
setup: function() {
Post = DS.Model.extend({
comments: hasMany({ async: true })
});
Comment = DS.Model.extend();
Post.toString = function() { return "Post"; };
Comment.toString = function() { return "Comment"; };
env = setupStore({ post: Post, comment: Comment });
},
teardown: function() {
run(env.container, 'destroy');
}
});
test("isLoading is false when request failed", function() {
env.adapter.find = function(store, type, id, snapshot) {
if (type === Post) {
return Ember.RSVP.resolve({ id: id, comments: [1, 2] });
}
// reject second find call for comment
if (type === Comment && id === '2') {
return Ember.RSVP.reject();
}
return Ember.RSVP.resolve({ id: id });
};
run(function() {
var post;
env.store.find('post', 1).then(function(lePost) {
post = lePost;
equal(post.get("isLoading"), false, "post is not loading anymore");
return post.get('comments');
}).then(null, function() {
equal(post.get("isLoading"), false, "post is not loading");
equal(post.get('comments').objectAt(0).get("isLoading"), false, "first comment is no more loading");
// fails here: isLoading is true but should be false
equal(post.get('comments').objectAt(1).get("isLoading"), false, "second comment is no more loading");
});
});
}); |
@pangratz LGTM, did you plan to fix this ? |
@sly7-7 yup, I give it a try. |
Okay, so after digging into the source I think the problem lies in the rejection handler of the If the var record = store.getById(typeClass, id) is changed to a A (currently failing) test case for this: test("When loading a record fails, the isLoading is set to false", function() {
env.adapter.find = function(store, type, id, snapshot) {
return Ember.RSVP.reject();
};
run(function() {
var leRecord = env.store.find('post', 1);
leRecord.then(null, function() {
// we know that such a record exists in the store, so we can use the private `recordForId`,
// as otherwise there is no way to to get the record, since `leRecord` is a rejected promise
var post = env.store.recordForId('post', 1);
equal(post.get("isLoading"), false, "post is not loading anymore");
});
});
}); Fixing the above failing test by using The question for rejected records via So, I hope my investigation report is understandable 😟. Fixing the case for the |
I think a better solution for fixing the |
I think findMany is gonna be handled by #2891 |
👍 |
@igorT sorry, I totally forgot to write a test for it 😱, I was very busy ... |
I have two Models
Model1-key --- hasMany -- Model2 (async)
when ember-data loads the records and one of the records request fail, its model
isLoading
property still always betrue
The text was updated successfully, but these errors were encountered: