FIX: topic owner should watch the new topic when moving posts to a new topic
This commit is contained in:
parent
a24b9981c6
commit
547b571d84
|
@ -34,6 +34,8 @@ class PostMover
|
|||
)
|
||||
DiscourseTagging.tag_topic_by_names(new_topic, Guardian.new(user), tags)
|
||||
move_posts_to new_topic
|
||||
force_user_to_watch_new_topic
|
||||
new_topic
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -223,4 +225,13 @@ class PostMover
|
|||
destination_topic.update_columns(attrs)
|
||||
end
|
||||
end
|
||||
|
||||
def force_user_to_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
|
||||
|
|
|
@ -58,9 +58,12 @@ RSpec.describe TopicsController do
|
|||
|
||||
describe 'moving to a new topic' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:user2) { Fabricate(:user) }
|
||||
let(:moderator) { Fabricate(:moderator) }
|
||||
let(:p1) { Fabricate(:post, user: user, post_number: 1) }
|
||||
let(:p2) { Fabricate(:post, user: user, post_number: 2, topic: p1.topic) }
|
||||
let(:p3) { Fabricate(:post, user: user2, post_number: 3, topic: p1.topic) }
|
||||
let(:p4) { Fabricate(:post, user: user2, post_number: 4, topic: p1.topic) }
|
||||
let!(:topic) { p1.topic }
|
||||
|
||||
it "raises an error without post_ids" do
|
||||
|
@ -116,6 +119,30 @@ RSpec.describe TopicsController do
|
|||
expect(Tag.all.pluck(:name)).to contain_exactly("tag1", "tag2")
|
||||
end
|
||||
|
||||
it "forces resulting topic owner to watch the new topic" do
|
||||
expect do
|
||||
post "/t/#{topic.id}/move-posts.json", params: {
|
||||
title: 'Logan is a good movie',
|
||||
post_ids: [p3.id, p4.id],
|
||||
}
|
||||
end.to change { Topic.count }.by(1)
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
result = ::JSON.parse(response.body)
|
||||
|
||||
expect(result['success']).to eq(true)
|
||||
new_topic = p3.reload.topic
|
||||
expect(result['url']).to eq(new_topic.relative_url)
|
||||
|
||||
expect(TopicUser.exists?(
|
||||
user_id: user2.id,
|
||||
topic_id: new_topic.id,
|
||||
notification_level: TopicUser.notification_levels[:watching],
|
||||
notifications_reason_id: TopicUser.notification_reasons[:created_topic]
|
||||
)).to eq(true)
|
||||
end
|
||||
|
||||
describe 'when topic has been deleted' do
|
||||
it 'should still be able to move posts' do
|
||||
PostDestroyer.new(Fabricate(:admin), topic.first_post).destroy
|
||||
|
|
Loading…
Reference in New Issue