mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FIX: Posts in a deleted topic couldn't be moved.
https://meta.discourse.org/t/moving-posts-to-new-topic/58436/4
This commit is contained in:
parent
a28704bcee
commit
477eb0591e
2 changed files with 40 additions and 10 deletions
|
@ -497,7 +497,7 @@ class TopicsController < ApplicationController
|
||||||
params.require(:topic_id)
|
params.require(:topic_id)
|
||||||
params.permit(:category_id)
|
params.permit(:category_id)
|
||||||
|
|
||||||
topic = Topic.find_by(id: params[:topic_id])
|
topic = Topic.with_deleted.find_by(id: params[:topic_id])
|
||||||
guardian.ensure_can_move_posts!(topic)
|
guardian.ensure_can_move_posts!(topic)
|
||||||
|
|
||||||
dest_topic = move_posts_to_destination(topic)
|
dest_topic = move_posts_to_destination(topic)
|
||||||
|
|
|
@ -64,7 +64,7 @@ describe TopicsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'moving to a new topic' do
|
describe 'moving to a new topic' do
|
||||||
let!(:user) { log_in(:moderator) }
|
let(:user) { log_in(:moderator) }
|
||||||
let(:p1) { Fabricate(:post, user: user) }
|
let(:p1) { Fabricate(:post, user: user) }
|
||||||
let(:topic) { p1.topic }
|
let(:topic) { p1.topic }
|
||||||
|
|
||||||
|
@ -79,18 +79,49 @@ describe TopicsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'success' do
|
context 'success' do
|
||||||
let(:p2) { Fabricate(:post, user: user) }
|
let(:user) { log_in(:admin) }
|
||||||
|
let(:p2) { Fabricate(:post, user: user, topic: topic) }
|
||||||
before do
|
|
||||||
Topic.any_instance.expects(:move_posts).with(user, [p2.id], title: 'blah', category_id: 123).returns(topic)
|
|
||||||
xhr :post, :move_posts, topic_id: topic.id, title: 'blah', post_ids: [p2.id], category_id: 123
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns success" do
|
it "returns success" do
|
||||||
|
p2
|
||||||
|
|
||||||
|
expect do
|
||||||
|
xhr :post, :move_posts,
|
||||||
|
topic_id: topic.id,
|
||||||
|
title: 'Logan is a good movie',
|
||||||
|
post_ids: [p2.id],
|
||||||
|
category_id: 123
|
||||||
|
end.to change { Topic.count }.by(1)
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
result = ::JSON.parse(response.body)
|
result = ::JSON.parse(response.body)
|
||||||
|
|
||||||
expect(result['success']).to eq(true)
|
expect(result['success']).to eq(true)
|
||||||
expect(result['url']).to be_present
|
expect(result['url']).to eq(Topic.last.relative_url)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'when topic has been deleted' do
|
||||||
|
it 'should still be able to move posts' do
|
||||||
|
PostDestroyer.new(user, topic.first_post).destroy
|
||||||
|
|
||||||
|
expect(topic.reload.deleted_at).to_not be_nil
|
||||||
|
|
||||||
|
expect do
|
||||||
|
xhr :post, :move_posts,
|
||||||
|
topic_id: topic.id,
|
||||||
|
title: 'Logan is a good movie',
|
||||||
|
post_ids: [p2.id],
|
||||||
|
category_id: 123
|
||||||
|
end.to change { Topic.count }.by(1)
|
||||||
|
|
||||||
|
expect(response).to be_success
|
||||||
|
|
||||||
|
result = JSON.parse(response.body)
|
||||||
|
|
||||||
|
expect(result['success']).to eq(true)
|
||||||
|
expect(result['url']).to eq(Topic.last.relative_url)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +162,6 @@ describe TopicsController do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe 'moving to an existing topic' do
|
describe 'moving to an existing topic' do
|
||||||
let!(:user) { log_in(:moderator) }
|
let!(:user) { log_in(:moderator) }
|
||||||
let(:p1) { Fabricate(:post, user: user) }
|
let(:p1) { Fabricate(:post, user: user) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue