From 8b4469a3f0192d90f660c3dcff6c88079cdaf639 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 16 Mar 2015 17:40:49 +1100 Subject: [PATCH] improve tests, ensure stream grows if all posts are loaded on commit --- .../javascripts/discourse/models/post-stream.js.es6 | 5 +---- test/javascripts/models/post-stream-test.js.es6 | 9 +++++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/models/post-stream.js.es6 b/app/assets/javascripts/discourse/models/post-stream.js.es6 index 2d188aa07..512c8d9ce 100644 --- a/app/assets/javascripts/discourse/models/post-stream.js.es6 +++ b/app/assets/javascripts/discourse/models/post-stream.js.es6 @@ -327,13 +327,10 @@ const PostStream = Ember.Object.extend({ // Commit the post we staged. Call this after a save succeeds. commitPost(post) { - // cleanup if (this.get('topic.id') === post.get('topic_id')) { if (this.get('loadedAllPosts')) { this.appendPost(post); - } else { - // I guess we might as well keep the data - this.storePost(post); + this.get('stream').addObject(post.get('id')); } } diff --git a/test/javascripts/models/post-stream-test.js.es6 b/test/javascripts/models/post-stream-test.js.es6 index ad20b8702..a3f7e1319 100644 --- a/test/javascripts/models/post-stream-test.js.es6 +++ b/test/javascripts/models/post-stream-test.js.es6 @@ -307,10 +307,10 @@ asyncTestDiscourse("loading a post's history", function() { test("staging and undoing a new post", function() { var postStream = buildStream(10101, [1]); - postStream.appendPost(Discourse.Post.create({id: 1, post_number: 1})); + postStream.appendPost(Discourse.Post.create({id: 1, post_number: 1, topic_id: 10101})); var user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321}); - var stagedPost = Discourse.Post.create({ raw: 'hello world this is my new post' }); + var stagedPost = Discourse.Post.create({ raw: 'hello world this is my new post', topic_id: 10101 }); var topic = postStream.get('topic'); topic.setProperties({ @@ -346,9 +346,9 @@ test("staging and undoing a new post", function() { test("staging and committing a post", function() { var postStream = buildStream(10101, [1]); - postStream.appendPost(Discourse.Post.create({id: 1, post_number: 1})); + postStream.appendPost(Discourse.Post.create({id: 1, post_number: 1, topic_id: 10101})); var user = Discourse.User.create({username: 'eviltrout', name: 'eviltrout', id: 321}); - var stagedPost = Discourse.Post.create({ raw: 'hello world this is my new post' }); + var stagedPost = Discourse.Post.create({ raw: 'hello world this is my new post', topic_id: 10101 }); var topic = postStream.get('topic'); topic.set('posts_count', 1); @@ -366,6 +366,7 @@ test("staging and committing a post", function() { postStream.commitPost(stagedPost); ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream"); ok(!postStream.get('loading'), "it is no longer loading"); + equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount"); var found = postStream.findLoadedPost(stagedPost.get('id'));