From a7c50039de62a6574b9bbfdba0b48e43f77e23de Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Thu, 1 Mar 2018 17:31:58 +0100 Subject: [PATCH] FIX: Allow changing post owner even when topic validations fail --- app/services/post_owner_changer.rb | 2 +- spec/services/post_owner_changer_spec.rb | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/services/post_owner_changer.rb b/app/services/post_owner_changer.rb index f419289faa0..730afcc8a34 100644 --- a/app/services/post_owner_changer.rb +++ b/app/services/post_owner_changer.rb @@ -31,7 +31,7 @@ class PostOwnerChanger first_post_created_at: @new_owner.reload.posts.order('created_at ASC').first&.created_at ) - @topic.save! + @topic.save!(validate: false) end end end diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rb index fb507dca7a0..e462bbe9bd7 100644 --- a/spec/services/post_owner_changer_spec.rb +++ b/spec/services/post_owner_changer_spec.rb @@ -65,9 +65,14 @@ describe PostOwnerChanger do it "changes the user even when the post does not pass validation" do p1.update_attribute(:raw, "foo") PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner! - p1.reload + expect(p1.reload.user).to eq(user_a) + end - expect(p1.user).to eq(user_a) + it "changes the user even when the topic does not pass validation" do + topic.update_column(:title, "short") + + PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: user_a, acting_user: editor).change_owner! + expect(p1.reload.user).to eq(user_a) end context "integration tests" do