From 984778d3acb209297e37681137c0d8d5131e83ec Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Mon, 3 Jul 2017 21:21:20 +0530 Subject: [PATCH] FIX: handle moving first post to a closed/archived topic --- app/models/post_mover.rb | 3 ++- spec/models/post_mover_spec.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 1f26293b2c5..1d70519eaf6 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -90,7 +90,8 @@ class PostMover raw: post.raw, topic_id: destination_topic.id, acting_user: user, - skip_validations: true + skip_validations: true, + guardian: Guardian.new(user) ) PostAction.copy(post, new_post) diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index 24631d880c0..28abdc88763 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -391,6 +391,19 @@ describe PostMover do end end + context "to an existing closed topic" do + let!(:destination_topic) { Fabricate(:topic, closed: true) } + + it "works correctly for admin" do + admin = Fabricate(:admin) + moved_to = topic.move_posts(admin, [p1.id, p2.id], destination_topic_id: destination_topic.id) + expect(moved_to).to be_present + + moved_to.reload + expect(moved_to.posts_count).to eq(2) + expect(moved_to.highest_post_number).to eq(2) + end + end end end