Skip to content

Commit

Permalink
Merge pull request #3043 from pangratz/fix_isLoading_flag_for_failed_…
Browse files Browse the repository at this point in the history
…find_request

Fix bug where record rejected via `find` stayed in loading state
  • Loading branch information
igorT committed May 5, 2015
2 parents 100ede1 + dac888c commit 3ba1f01
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
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();
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
// 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");
});
});
});

0 comments on commit 3ba1f01

Please sign in to comment.