2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
describe PostMover do
|
|
|
|
|
2016-01-08 18:53:52 +08:00
|
|
|
describe '#move_types' do
|
|
|
|
context "verify enum sequence" do
|
|
|
|
before do
|
|
|
|
@move_types = PostMover.move_types
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'new_topic' should be at 1st position" do
|
|
|
|
expect(@move_types[:new_topic]).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "'existing_topic' should be at 2nd position" do
|
|
|
|
expect(@move_types[:existing_topic]).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-17 14:40:15 +08:00
|
|
|
context 'move_posts' do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:another_user) { Fabricate(:evil_trout) }
|
|
|
|
let(:category) { Fabricate(:category, user: user) }
|
2013-10-30 03:30:06 +08:00
|
|
|
let!(:topic) { Fabricate(:topic, user: user) }
|
2013-07-17 14:40:15 +08:00
|
|
|
let!(:p1) { Fabricate(:post, topic: topic, user: user) }
|
2017-03-06 15:04:10 +08:00
|
|
|
|
|
|
|
let!(:p2) do
|
|
|
|
Fabricate(:post,
|
|
|
|
topic: topic,
|
|
|
|
user: another_user,
|
|
|
|
raw: "Has a link to [evil trout](http://eviltrout.com) which is a cool site.",
|
|
|
|
reply_to_post_number: p1.post_number)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:p3) { Fabricate(:post, topic: topic, reply_to_post_number: p1.post_number, user: user) }
|
|
|
|
let!(:p4) { Fabricate(:post, topic: topic, reply_to_post_number: p2.post_number, user: user) }
|
|
|
|
let!(:p5) { Fabricate(:post) }
|
2017-06-02 06:00:04 +08:00
|
|
|
let(:p6) { Fabricate(:post, topic: topic) }
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
before do
|
2016-07-13 23:34:21 +08:00
|
|
|
p1.replies << p3
|
|
|
|
p2.replies << p4
|
2016-12-22 12:03:40 +08:00
|
|
|
UserActionCreator.enable
|
2013-07-17 14:40:15 +08:00
|
|
|
@like = PostAction.act(another_user, p4, PostActionType.types[:like])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'success' do
|
|
|
|
|
2017-06-02 06:00:04 +08:00
|
|
|
it "correctly handles notifications and bread crumbs" do
|
|
|
|
old_topic = p2.topic
|
|
|
|
|
|
|
|
old_topic_id = p2.topic_id
|
|
|
|
|
|
|
|
topic.move_posts(user, [p2.id, p4.id, p6.id], title: "new testing topic name")
|
|
|
|
|
|
|
|
p2.reload
|
|
|
|
expect(p2.topic_id).not_to eq(old_topic_id)
|
|
|
|
expect(p2.reply_to_post_number).to eq(nil)
|
|
|
|
expect(p2.reply_to_user_id).to eq(nil)
|
|
|
|
|
|
|
|
notification = p2.user.notifications.where(notification_type: Notification.types[:moved_post]).first
|
|
|
|
|
|
|
|
expect(notification.topic_id).to eq(p2.topic_id)
|
|
|
|
expect(notification.post_number).to eq(1)
|
|
|
|
|
|
|
|
# no message for person who made the move
|
|
|
|
expect(p4.user.notifications.where(notification_type: Notification.types[:moved_post]).length).to eq(0)
|
|
|
|
|
|
|
|
# notify at the right spot in the stream
|
|
|
|
notification = p6.user.notifications.where(notification_type: Notification.types[:moved_post]).first
|
|
|
|
|
|
|
|
expect(notification.topic_id).to eq(p2.topic_id)
|
|
|
|
|
|
|
|
# this is the 3rd post we moved
|
|
|
|
expect(notification.post_number).to eq(3)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
2017-06-02 06:00:04 +08:00
|
|
|
old_topic.reload
|
|
|
|
move_message = old_topic.posts.find_by(post_number: 2)
|
|
|
|
expect(move_message.post_type).to eq(Post.types[:small_action])
|
|
|
|
expect(move_message.raw).to include("3 posts were split")
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "errors" do
|
|
|
|
|
|
|
|
it "raises an error when one of the posts doesn't exist" do
|
2014-12-31 22:55:03 +08:00
|
|
|
expect { topic.move_posts(user, [1003], title: "new testing topic name") }.to raise_error(Discourse::InvalidParameters)
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it "raises an error and does not create a topic if no posts were moved" do
|
|
|
|
Topic.count.tap do |original_topic_count|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect {
|
2013-07-17 14:40:15 +08:00
|
|
|
topic.move_posts(user, [], title: "new testing topic name")
|
2014-12-31 22:55:03 +08:00
|
|
|
}.to raise_error(Discourse::InvalidParameters)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
expect(Topic.count).to eq original_topic_count
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "successfully moved" do
|
|
|
|
before do
|
2017-11-18 05:08:31 +08:00
|
|
|
TopicUser.update_last_read(user, topic.id, p4.post_number, p4.post_number, 0)
|
2013-07-17 14:40:15 +08:00
|
|
|
TopicLink.extract_from(p2)
|
|
|
|
end
|
|
|
|
|
2016-07-13 23:34:21 +08:00
|
|
|
context "post replies" do
|
|
|
|
describe "when a post with replies is moved" do
|
|
|
|
it "should update post replies correctly" do
|
|
|
|
topic.move_posts(
|
|
|
|
user,
|
|
|
|
[p2.id],
|
2016-08-04 23:49:44 +08:00
|
|
|
title: 'GOT is a very addictive show', category_id: category.id
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(p2.reload.replies).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't raise errors with deleted replies" do
|
|
|
|
p4.trash!
|
|
|
|
topic.move_posts(
|
|
|
|
user,
|
|
|
|
[p2.id],
|
|
|
|
title: 'GOT is a very addictive show', category_id: category.id
|
2016-07-13 23:34:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(p2.reload.replies).to eq([])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when replies of a post have been moved" do
|
|
|
|
it "should update post replies correctly" do
|
|
|
|
p5 = Fabricate(
|
|
|
|
:post,
|
|
|
|
topic: topic,
|
|
|
|
reply_to_post_number: p2.post_number,
|
|
|
|
user: another_user
|
|
|
|
)
|
|
|
|
|
|
|
|
p2.replies << p5
|
|
|
|
|
|
|
|
topic.move_posts(
|
|
|
|
user,
|
|
|
|
[p4.id],
|
2016-08-04 23:49:44 +08:00
|
|
|
title: 'GOT is a very addictive show', category_id: category.id
|
2016-07-13 23:34:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(p2.reload.replies).to eq([p5])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "when only one reply is left behind" do
|
|
|
|
it "should update post replies correctly" do
|
|
|
|
p5 = Fabricate(
|
|
|
|
:post,
|
|
|
|
topic: topic,
|
|
|
|
reply_to_post_number: p2.post_number,
|
|
|
|
user: another_user
|
|
|
|
)
|
|
|
|
|
|
|
|
p2.replies << p5
|
|
|
|
|
|
|
|
topic.move_posts(
|
|
|
|
user,
|
|
|
|
[p2.id, p4.id],
|
2016-08-04 23:49:44 +08:00
|
|
|
title: 'GOT is a very addictive show', category_id: category.id
|
2016-07-13 23:34:21 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(p2.reload.replies).to eq([p4])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-17 14:40:15 +08:00
|
|
|
context "to a new topic" do
|
|
|
|
|
|
|
|
it "works correctly" do
|
2015-12-30 05:01:49 +08:00
|
|
|
topic.expects(:add_moderator_post).once
|
|
|
|
new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id)
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_topic).to be_present
|
2015-11-07 12:17:47 +08:00
|
|
|
expect(new_topic.featured_user1_id).to eq(p4.user_id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_topic.like_count).to eq(1)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_topic.category).to eq(category)
|
|
|
|
expect(topic.featured_user1_id).to be_blank
|
|
|
|
expect(new_topic.posts.by_post_number).to match_array([p2, p4])
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
new_topic.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_topic.posts_count).to eq(2)
|
|
|
|
expect(new_topic.highest_post_number).to eq(2)
|
|
|
|
expect(new_topic.last_post_user_id).to eq(new_topic.posts.last.user_id)
|
2013-07-17 14:40:15 +08:00
|
|
|
expect(new_topic.last_posted_at).to be_present
|
|
|
|
|
|
|
|
p2.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p2.sort_order).to eq(1)
|
|
|
|
expect(p2.post_number).to eq(1)
|
|
|
|
expect(p2.topic_links.first.topic_id).to eq(new_topic.id)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
p4.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p4.post_number).to eq(2)
|
|
|
|
expect(p4.sort_order).to eq(2)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
topic.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.featured_user1_id).to be_blank
|
|
|
|
expect(topic.like_count).to eq(0)
|
|
|
|
expect(topic.posts_count).to eq(2)
|
|
|
|
expect(topic.posts.by_post_number).to match_array([p1, p3])
|
|
|
|
expect(topic.highest_post_number).to eq(p3.post_number)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# both the like and was_liked user actions should be correct
|
2014-05-06 21:41:59 +08:00
|
|
|
action = UserAction.find_by(user_id: another_user.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(action.target_topic_id).to eq(new_topic.id)
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
2015-12-30 05:01:49 +08:00
|
|
|
|
|
|
|
it "moving all posts will close the topic" do
|
|
|
|
topic.expects(:add_moderator_post).twice
|
|
|
|
new_topic = topic.move_posts(user, [p1.id, p2.id, p3.id, p4.id], title: "new testing topic name", category_id: category.id)
|
|
|
|
expect(new_topic).to be_present
|
|
|
|
|
|
|
|
topic.reload
|
|
|
|
expect(topic.closed).to eq(true)
|
|
|
|
end
|
2017-03-06 15:04:10 +08:00
|
|
|
|
|
|
|
it 'does not move posts that do not belong to the existing topic' do
|
|
|
|
new_topic = topic.move_posts(
|
|
|
|
user, [p2.id, p3.id, p5.id], title: 'Logan is a pretty good movie'
|
|
|
|
)
|
|
|
|
|
2017-03-14 14:43:48 +08:00
|
|
|
expect(new_topic.posts.pluck(:id).sort).to eq([p2.id, p3.id].sort)
|
2017-03-06 15:04:10 +08:00
|
|
|
end
|
2017-09-14 21:52:09 +08:00
|
|
|
|
|
|
|
it "uses default locale for moderator post" do
|
|
|
|
I18n.locale = 'de'
|
|
|
|
|
|
|
|
new_topic = topic.move_posts(user, [p2.id, p4.id], title: "new testing topic name", category_id: category.id)
|
|
|
|
post = Post.find_by(topic_id: topic.id, post_type: Post.types[:small_action])
|
|
|
|
|
|
|
|
expected_text = I18n.with_locale(:en) do
|
|
|
|
I18n.t("move_posts.new_topic_moderator_post",
|
|
|
|
count: 2,
|
|
|
|
topic_link: "[#{new_topic.title}](#{new_topic.relative_url})")
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(post.raw).to eq(expected_text)
|
|
|
|
end
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "to an existing topic" do
|
2017-07-28 09:20:09 +08:00
|
|
|
let!(:destination_topic) { Fabricate(:topic, user: user) }
|
2013-07-17 14:40:15 +08:00
|
|
|
let!(:destination_op) { Fabricate(:post, topic: destination_topic, user: user) }
|
|
|
|
|
|
|
|
it "works correctly" do
|
2015-12-30 05:01:49 +08:00
|
|
|
topic.expects(:add_moderator_post).once
|
|
|
|
moved_to = topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(moved_to).to eq(destination_topic)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# Check out new topic
|
|
|
|
moved_to.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(moved_to.posts_count).to eq(3)
|
|
|
|
expect(moved_to.highest_post_number).to eq(3)
|
2015-11-07 12:17:47 +08:00
|
|
|
expect(moved_to.user_id).to eq(p1.user_id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(moved_to.like_count).to eq(1)
|
|
|
|
expect(moved_to.category_id).to eq(SiteSetting.uncategorized_category_id)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# Posts should be re-ordered
|
|
|
|
p2.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p2.sort_order).to eq(2)
|
|
|
|
expect(p2.post_number).to eq(2)
|
|
|
|
expect(p2.topic_id).to eq(moved_to.id)
|
|
|
|
expect(p2.reply_count).to eq(1)
|
|
|
|
expect(p2.reply_to_post_number).to eq(nil)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
p4.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p4.post_number).to eq(3)
|
|
|
|
expect(p4.sort_order).to eq(3)
|
|
|
|
expect(p4.topic_id).to eq(moved_to.id)
|
|
|
|
expect(p4.reply_count).to eq(0)
|
|
|
|
expect(p4.reply_to_post_number).to eq(2)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# Check out the original topic
|
|
|
|
topic.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.posts_count).to eq(2)
|
|
|
|
expect(topic.highest_post_number).to eq(3)
|
|
|
|
expect(topic.featured_user1_id).to be_blank
|
|
|
|
expect(topic.like_count).to eq(0)
|
|
|
|
expect(topic.posts_count).to eq(2)
|
|
|
|
expect(topic.posts.by_post_number).to match_array([p1, p3])
|
|
|
|
expect(topic.highest_post_number).to eq(p3.post_number)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
2017-06-02 23:20:40 +08:00
|
|
|
# Should notify correctly
|
|
|
|
notification = p2.user.notifications.where(notification_type: Notification.types[:moved_post]).first
|
|
|
|
|
|
|
|
expect(notification.topic_id).to eq(p2.topic_id)
|
|
|
|
expect(notification.post_number).to eq(p2.post_number)
|
|
|
|
|
2013-07-17 14:40:15 +08:00
|
|
|
# Should update last reads
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
2015-12-30 05:01:49 +08:00
|
|
|
|
|
|
|
it "moving all posts will close the topic" do
|
|
|
|
topic.expects(:add_moderator_post).twice
|
|
|
|
moved_to = topic.move_posts(user, [p1.id, p2.id, p3.id, p4.id], destination_topic_id: destination_topic.id)
|
|
|
|
expect(moved_to).to be_present
|
|
|
|
|
|
|
|
topic.reload
|
|
|
|
expect(topic.closed).to eq(true)
|
|
|
|
end
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
context "moving the first post" do
|
|
|
|
|
|
|
|
it "copies the OP, doesn't delete it" do
|
2015-12-30 05:01:49 +08:00
|
|
|
topic.expects(:add_moderator_post).once
|
|
|
|
new_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name")
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_topic).to be_present
|
|
|
|
expect(new_topic.posts.by_post_number.first.raw).to eq(p1.raw)
|
|
|
|
expect(new_topic.posts_count).to eq(2)
|
|
|
|
expect(new_topic.highest_post_number).to eq(2)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# First post didn't move
|
|
|
|
p1.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p1.sort_order).to eq(1)
|
|
|
|
expect(p1.post_number).to eq(1)
|
2017-02-10 22:35:04 +08:00
|
|
|
expect(p1.topic_id).to eq(topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p1.reply_count).to eq(0)
|
2014-08-21 02:14:56 +08:00
|
|
|
|
|
|
|
# New first post
|
|
|
|
new_first = new_topic.posts.where(post_number: 1).first
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(new_first.reply_count).to eq(1)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
# Second post is in a new topic
|
|
|
|
p2.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p2.post_number).to eq(2)
|
|
|
|
expect(p2.sort_order).to eq(2)
|
2017-02-10 22:35:04 +08:00
|
|
|
expect(p2.topic_id).to eq(new_topic.id)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p2.reply_to_post_number).to eq(1)
|
|
|
|
expect(p2.reply_count).to eq(0)
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
topic.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(topic.posts.by_post_number).to match_array([p1, p3, p4])
|
|
|
|
expect(topic.highest_post_number).to eq(p4.post_number)
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
2017-02-10 22:35:04 +08:00
|
|
|
it "preserves post actions in the new post" do
|
|
|
|
PostAction.act(another_user, p1, PostActionType.types[:like])
|
|
|
|
|
|
|
|
new_topic = topic.move_posts(user, [p1.id], title: "new testing topic name")
|
|
|
|
new_post = new_topic.posts.where(post_number: 1).first
|
|
|
|
|
|
|
|
expect(new_topic.like_count).to eq(1)
|
|
|
|
expect(new_post.like_count).to eq(1)
|
|
|
|
expect(new_post.post_actions.size).to eq(1)
|
|
|
|
end
|
|
|
|
|
2017-06-07 18:04:48 +08:00
|
|
|
it "preserves the custom_fields in the new post" do
|
|
|
|
custom_fields = { "some_field" => 'payload' }
|
|
|
|
p1.custom_fields = custom_fields
|
|
|
|
p1.save_custom_fields
|
|
|
|
|
|
|
|
new_topic = topic.move_posts(user, [p1.id], title: "new testing topic name")
|
|
|
|
|
|
|
|
expect(new_topic.first_post.custom_fields).to eq(custom_fields)
|
|
|
|
end
|
|
|
|
|
2013-07-17 14:40:15 +08:00
|
|
|
end
|
|
|
|
|
2014-08-21 00:28:34 +08:00
|
|
|
context "to an existing topic with a deleted post" do
|
|
|
|
|
2015-12-30 05:01:49 +08:00
|
|
|
before do
|
|
|
|
topic.expects(:add_moderator_post)
|
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
let!(:destination_topic) { Fabricate(:topic, user: user) }
|
2014-08-21 00:28:34 +08:00
|
|
|
let!(:destination_op) { Fabricate(:post, topic: destination_topic, user: user) }
|
|
|
|
let!(:destination_deleted_reply) { Fabricate(:post, topic: destination_topic, user: another_user) }
|
2017-07-28 09:20:09 +08:00
|
|
|
let(:moved_to) { topic.move_posts(user, [p2.id, p4.id], destination_topic_id: destination_topic.id) }
|
2014-08-21 00:28:34 +08:00
|
|
|
|
|
|
|
it "works correctly" do
|
|
|
|
destination_deleted_reply.trash!
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(moved_to).to eq(destination_topic)
|
2014-08-21 00:28:34 +08:00
|
|
|
|
|
|
|
# Check out new topic
|
|
|
|
moved_to.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(moved_to.posts_count).to eq(3)
|
|
|
|
expect(moved_to.highest_post_number).to eq(4)
|
2014-08-21 00:28:34 +08:00
|
|
|
|
|
|
|
# Posts should be re-ordered
|
|
|
|
p2.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p2.sort_order).to eq(3)
|
|
|
|
expect(p2.post_number).to eq(3)
|
|
|
|
expect(p2.topic_id).to eq(moved_to.id)
|
|
|
|
expect(p2.reply_count).to eq(1)
|
|
|
|
expect(p2.reply_to_post_number).to eq(nil)
|
2014-08-21 00:28:34 +08:00
|
|
|
|
|
|
|
p4.reload
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(p4.post_number).to eq(4)
|
|
|
|
expect(p4.sort_order).to eq(4)
|
|
|
|
expect(p4.topic_id).to eq(moved_to.id)
|
|
|
|
expect(p4.reply_to_post_number).to eq(p2.post_number)
|
2014-08-21 00:28:34 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 23:51:20 +08:00
|
|
|
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
|
2013-07-17 14:40:15 +08:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|