mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Update post replies when we move posts. (#4324)
This commit is contained in:
committed by
Régis Hanol
parent
41cbdb5dfa
commit
5fed886c8f
@@ -29,6 +29,8 @@ describe PostMover do
|
||||
let!(:p4) { Fabricate(:post, topic: topic, reply_to_post_number: p2.post_number, user: user)}
|
||||
|
||||
before do
|
||||
p1.replies << p3
|
||||
p2.replies << p4
|
||||
# add a like to a post, enable observers so we get user actions
|
||||
ActiveRecord::Base.observers.enable :all
|
||||
@like = PostAction.act(another_user, p4, PostActionType.types[:like])
|
||||
@@ -72,6 +74,62 @@ describe PostMover do
|
||||
TopicLink.extract_from(p2)
|
||||
end
|
||||
|
||||
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],
|
||||
title: 'GOT is a very addictive showw', category_id: category.id
|
||||
)
|
||||
|
||||
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],
|
||||
title: 'GOT is a very addictive showw', category_id: category.id
|
||||
)
|
||||
|
||||
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],
|
||||
title: 'GOT is a very addictive showw', category_id: category.id
|
||||
)
|
||||
|
||||
expect(p2.reload.replies).to eq([p4])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "to a new topic" do
|
||||
|
||||
it "works correctly" do
|
||||
|
||||
@@ -1,8 +1,27 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe PostReply do
|
||||
let(:topic) { Fabricate(:topic) }
|
||||
let(:post) { Fabricate(:post, topic: topic) }
|
||||
let(:other_post) { Fabricate(:post, topic: topic) }
|
||||
|
||||
it { is_expected.to belong_to :post }
|
||||
it { is_expected.to belong_to :reply }
|
||||
|
||||
context "validation" do
|
||||
it "should ensure that the posts belong in the same topic" do
|
||||
expect(PostReply.new(post: post, reply: other_post)).to be_valid
|
||||
|
||||
other_topic = Fabricate(:topic)
|
||||
other_post.update_attributes!(topic_id: other_topic.id)
|
||||
other_post.reload
|
||||
|
||||
post_reply = PostReply.new(post: post, reply: other_post)
|
||||
expect(post_reply).to_not be_valid
|
||||
|
||||
expect(post_reply.errors[:base]).to include(
|
||||
I18n.t("activerecord.errors.models.post_reply.base.different_topic")
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user