Merge pull request #6106 from OsamaSayegh/watch-when-splitting

FIX: topic owner should watch the new topic when moving posts to a new topic
This commit is contained in:
Guo Xiang Tan 2018-07-20 15:18:59 +08:00 committed by GitHub
commit 7cf6c2825e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View File

@ -34,6 +34,8 @@ class PostMover
)
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
move_posts_to new_topic
watch_new_topic
new_topic
end
end
@ -223,4 +225,13 @@ class PostMover
destination_topic.update_columns(attrs)
end
end
def watch_new_topic
TopicUser.change(
destination_topic.user,
destination_topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:created_topic]
)
end
end

View File

@ -264,6 +264,19 @@ describe PostMover do
moderator_post = topic.posts.last
expect(moderator_post.raw).to include("2 posts were split")
end
it "forces resulting topic owner to watch the new topic" do
new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id)
expect(new_topic.posts_count).to eq(2)
expect(TopicUser.exists?(
user_id: another_user,
topic_id: new_topic.id,
notification_level: TopicUser.notification_levels[:watching],
notifications_reason_id: TopicUser.notification_reasons[:created_topic]
)).to eq(true)
end
end
context "to an existing topic" do