FIX: incoming and outgoing emails got lost when post was moved

This commit is contained in:
Gerhard Schlager
2017-11-24 11:13:19 +01:00
parent 44333c5de3
commit b3094e9954
2 changed files with 75 additions and 0 deletions

View File

@ -334,6 +334,49 @@ describe PostMover do
end
end
shared_examples "moves email related stuff" do
it "moves incoming email" do
Fabricate(:incoming_email, user: old_post.user, topic: old_post.topic, post: old_post)
new_topic = topic.move_posts(user, [old_post.id], title: "new testing topic name")
new_post = new_topic.first_post
email = new_post.incoming_email
expect(email).to be_present
expect(email.topic_id).to eq(new_topic.id)
expect(email.post_id).to eq(new_post.id)
expect(old_post.reload.incoming_email).to_not be_present unless old_post.id == new_post.id
end
it "moves email log entries" do
old_topic = old_post.topic
Fabricate(:email_log, user: old_post.user, topic: old_topic, post: old_post, email_type: :mailing_list)
Fabricate(:email_log, user: old_post.user, topic: old_topic, post: old_post, email_type: :mailing_list)
Fabricate(:email_log, user: old_post.user, post: old_post, email_type: :mailing_list)
expect(EmailLog.where(topic_id: old_topic.id, post_id: old_post.id).count).to eq(2)
expect(EmailLog.where(topic_id: nil, post_id: old_post.id).count).to eq(1)
new_topic = old_topic.move_posts(user, [old_post.id], title: "new testing topic name")
new_post = new_topic.first_post
expect(EmailLog.where(topic_id: old_topic.id, post_id: old_post.id).count).to eq(0)
expect(EmailLog.where(topic_id: new_topic.id, post_id: new_post.id).count).to eq(3)
end
it "preserves post attributes" do
old_post.update_columns(cook_method: Post.cook_methods[:email], via_email: true, raw_email: "raw email content")
new_topic = old_post.topic.move_posts(user, [old_post.id], title: "new testing topic name")
new_post = new_topic.first_post
expect(new_post.cook_method).to eq(Post.cook_methods[:email])
expect(new_post.via_email).to eq(true)
expect(new_post.raw_email).to eq("raw email content")
end
end
context "moving the first post" do
it "copies the OP, doesn't delete it" do
@ -390,6 +433,15 @@ describe PostMover do
expect(new_topic.first_post.custom_fields).to eq(custom_fields)
end
include_examples "moves email related stuff" do
let!(:old_post) { p1 }
end
end
context "moving replies" do
include_examples "moves email related stuff" do
let!(:old_post) { p3 }
end
end
context "to an existing topic with a deleted post" do