From 6c374cf158d9eff4412ff7ed10d2390b2cd6ba38 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 16 Feb 2022 09:52:20 +0800 Subject: [PATCH] DEV: Improve ArgumenError raised in PostOwnerChanger. (#15907) Currently, it doesn't provide any context about the arguement which caused the error. --- app/services/post_owner_changer.rb | 4 +++- spec/services/post_owner_changer_spec.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/services/post_owner_changer.rb b/app/services/post_owner_changer.rb index 7b6929c5d40..c8f8e8f7f4c 100644 --- a/app/services/post_owner_changer.rb +++ b/app/services/post_owner_changer.rb @@ -9,7 +9,9 @@ class PostOwnerChanger @acting_user = params[:acting_user] @skip_revision = params[:skip_revision] || false - raise ArgumentError unless @post_ids && @topic && @new_owner && @acting_user + [:post_ids, :topic, :new_owner, :acting_user].each do |arg| + raise ArgumentError.new(arg) if self.instance_variable_get("@#{arg}").blank? + end end def change_owner! diff --git a/spec/services/post_owner_changer_spec.rb b/spec/services/post_owner_changer_spec.rb index 5af14753f67..5353707037f 100644 --- a/spec/services/post_owner_changer_spec.rb +++ b/spec/services/post_owner_changer_spec.rb @@ -14,7 +14,7 @@ describe PostOwnerChanger do it "raises an error with a parameter missing" do expect { PostOwnerChanger.new(post_ids: [p1.id], topic_id: topic.id, new_owner: nil, acting_user: editor) - }.to raise_error(ArgumentError) + }.to raise_error(ArgumentError, /new_owner/) end it "calls PostRevisor" do