Skip to content

Commit

Permalink
FIX: Posts in a deleted topic couldn't be moved.
Browse files Browse the repository at this point in the history
  • Loading branch information
tgxworld committed Mar 6, 2017
1 parent a28704b commit 477eb05
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/topics_controller.rb
Expand Up @@ -497,7 +497,7 @@ def move_posts
params.require(:topic_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)

dest_topic = move_posts_to_destination(topic)
Expand Down
48 changes: 39 additions & 9 deletions spec/controllers/topics_controller_spec.rb
Expand Up @@ -64,7 +64,7 @@ def topics_controller_show_gen_perm_tests(expected, ctx)
end

describe 'moving to a new topic' do
let!(:user) { log_in(:moderator) }
let(:user) { log_in(:moderator) }
let(:p1) { Fabricate(:post, user: user) }
let(:topic) { p1.topic }

Expand All @@ -79,18 +79,49 @@ def topics_controller_show_gen_perm_tests(expected, ctx)
end

context 'success' do
let(:p2) { Fabricate(:post, user: user) }

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
let(:user) { log_in(:admin) }
let(:p2) { Fabricate(:post, user: user, topic: topic) }

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

result = ::JSON.parse(response.body)

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

Expand Down Expand Up @@ -131,7 +162,6 @@ def topics_controller_show_gen_perm_tests(expected, ctx)

end


describe 'moving to an existing topic' do
let!(:user) { log_in(:moderator) }
let(:p1) { Fabricate(:post, user: user) }
Expand Down

0 comments on commit 477eb05

Please sign in to comment.