Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #3043 from pangratz/fix_isLoading_flag_for_failed_…

…find_request

Fix bug where record rejected via `find` stayed in loading state
commit 3ba1f014700ba8226321bb6a899447ffb97fddc1 2 parents 100ede1 + dac888c
@igorT igorT authored
View
10 packages/ember-data/lib/system/store/finders.js
@@ -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 + "'");
}
View
39 packages/ember-data/tests/integration/records/load-test.js
@@ -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");
+ });
+ });
+});
Please sign in to comment.
Something went wrong with that request. Please try again.