From 0ecdf900230eee21beaf54b80428bd18768127ae Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 8 Feb 2018 13:36:13 +0100 Subject: [PATCH] FIX: Validations could prevent moving posts --- app/models/post_mover.rb | 3 ++- spec/models/post_mover_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/post_mover.rb b/app/models/post_mover.rb index 79393fbf5db..7544a87ef15 100644 --- a/app/models/post_mover.rb +++ b/app/models/post_mover.rb @@ -128,7 +128,8 @@ class PostMover update[:reply_to_user_id] = nil end - post.update(update) + post.attributes = update + post.save(validate: false) move_incoming_emails(post, post) move_email_logs(post, post) diff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rb index ded0639fca4..d48520a64e0 100644 --- a/spec/models/post_mover_spec.rb +++ b/spec/models/post_mover_spec.rb @@ -499,6 +499,17 @@ describe PostMover do end end + it "skips validations when moving posts" do + p1.update_attribute(:raw, "foo") + p2.update_attribute(:raw, "bar") + + new_topic = topic.move_posts(user, [p1.id, p2.id], title: "new testing topic name") + + expect(new_topic).to be_present + expect(new_topic.posts.by_post_number.first.raw).to eq(p1.raw) + expect(new_topic.posts.by_post_number.last.raw).to eq(p2.raw) + expect(new_topic.posts_count).to eq(2) + end end end end