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

Fix bug where record rejected via find stayed in loading state #3043

Merged
merged 1 commit into from
May 5, 2015
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
10 changes: 4 additions & 6 deletions packages/ember-data/lib/system/store/finders.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ export function _find(adapter, store, typeClass, id, record) {
return store.push(typeClass, payload);
});
}, function(error) {
var record = store.getById(typeClass, id);
if (record) {
record.notFound();
if (get(record, 'isEmpty')) {
store.unloadRecord(record);
}
record.notFound();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line has been added in 63795a4, where the record parameter was not available. I guess that's the reason why a var record = store.getById(typeClass, id) has been used here; the record parameter is added in 51728a8. So I think reusing the param down below is save...

if (get(record, 'isEmpty')) {
store.unloadRecord(record);
}

throw error;
}, "DS: Extract payload of '" + typeClass + "'");
}
Expand Down
39 changes: 39 additions & 0 deletions packages/ember-data/tests/integration/records/load-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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("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() {
env.store.find('post', 1).then(null, function() {
// store.recordForId is private, but there is currently no other way to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it's ok to use private methods like this in the test

// get the specific record instance, since it is not passed to this
// rejection handler
var post = env.store.recordForId('post', 1);

equal(post.get("isLoading"), false, "post is not loading anymore");
});
});
});