mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:01:25 +08:00
improve tests, ensure stream grows if all posts are loaded on commit
This commit is contained in:
@ -327,13 +327,10 @@ const PostStream = Ember.Object.extend({
|
|||||||
// Commit the post we staged. Call this after a save succeeds.
|
// Commit the post we staged. Call this after a save succeeds.
|
||||||
commitPost(post) {
|
commitPost(post) {
|
||||||
|
|
||||||
// cleanup
|
|
||||||
if (this.get('topic.id') === post.get('topic_id')) {
|
if (this.get('topic.id') === post.get('topic_id')) {
|
||||||
if (this.get('loadedAllPosts')) {
|
if (this.get('loadedAllPosts')) {
|
||||||
this.appendPost(post);
|
this.appendPost(post);
|
||||||
} else {
|
this.get('stream').addObject(post.get('id'));
|
||||||
// I guess we might as well keep the data
|
|
||||||
this.storePost(post);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,10 +307,10 @@ asyncTestDiscourse("loading a post's history", function() {
|
|||||||
|
|
||||||
test("staging and undoing a new post", function() {
|
test("staging and undoing a new post", function() {
|
||||||
var postStream = buildStream(10101, [1]);
|
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 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');
|
var topic = postStream.get('topic');
|
||||||
topic.setProperties({
|
topic.setProperties({
|
||||||
@ -346,9 +346,9 @@ test("staging and undoing a new post", function() {
|
|||||||
|
|
||||||
test("staging and committing a post", function() {
|
test("staging and committing a post", function() {
|
||||||
var postStream = buildStream(10101, [1]);
|
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 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');
|
var topic = postStream.get('topic');
|
||||||
topic.set('posts_count', 1);
|
topic.set('posts_count', 1);
|
||||||
@ -366,6 +366,7 @@ test("staging and committing a post", function() {
|
|||||||
postStream.commitPost(stagedPost);
|
postStream.commitPost(stagedPost);
|
||||||
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
ok(postStream.get('posts').contains(stagedPost), "the post is still in the stream");
|
||||||
ok(!postStream.get('loading'), "it is no longer loading");
|
ok(!postStream.get('loading'), "it is no longer loading");
|
||||||
|
|
||||||
equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount");
|
equal(postStream.get('filteredPostsCount'), 2, "it increases the filteredPostsCount");
|
||||||
|
|
||||||
var found = postStream.findLoadedPost(stagedPost.get('id'));
|
var found = postStream.findLoadedPost(stagedPost.get('id'));
|
||||||
|
Reference in New Issue
Block a user