Skip to content

A platform for community discussion. Free, open, simple.

FIX: ensure `remove_reviewable_ids` is always an array (#37131)

Alan Guo Xiang Tan3324fe4fef78
diff --git a/frontend/discourse/app/components/reviewable-refresh/item.gjs b/frontend/discourse/app/components/reviewable-refresh/item.gjs
index 12402d88460..26ff31bdaca 100644
--- a/frontend/discourse/app/components/reviewable-refresh/item.gjs
+++ b/frontend/discourse/app/components/reviewable-refresh/item.gjs
@@ -378,7 +378,7 @@ export default class ReviewableItem extends Component {
@bind
_updateStatus(data) {
- if (data.remove_reviewable_ids.includes(this.reviewable.id)) {
+ if (data.remove_reviewable_ids?.includes(this.reviewable.id)) {
delete data.remove_reviewable_ids;
this._performResult(data, {}, this.reviewable);
}
@@ -467,7 +467,7 @@ export default class ReviewableItem extends Component {
});
}
- if (this.remove && result.remove_reviewable_ids) {
+ if (this.remove && result.remove_reviewable_ids?.length > 0) {
this.remove(result.remove_reviewable_ids);
} else {
return this.store.find("reviewable", reviewable.id);
diff --git a/lib/reviewable/perform_result.rb b/lib/reviewable/perform_result.rb
index 623497026d6..cf65993c936 100644
--- a/lib/reviewable/perform_result.rb
+++ b/lib/reviewable/perform_result.rb
@@ -17,7 +17,7 @@ class Reviewable < ActiveRecord::Base
def initialize(reviewable, status)
@status = status
@reviewable = reviewable
- @remove_reviewable_ids = [reviewable.id] if success?
+ @remove_reviewable_ids = success? ? [reviewable.id] : []
end
def created_post=(created_post)
diff --git a/spec/lib/reviewable/perform_result_spec.rb b/spec/lib/reviewable/perform_result_spec.rb
new file mode 100644
index 00000000000..ac60e7a06d8
--- /dev/null
+++ b/spec/lib/reviewable/perform_result_spec.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+RSpec.describe Reviewable::PerformResult do
+ fab!(:reviewable, :reviewable_queued_post)
+
+ describe "#initialize" do
+ it "sets remove_reviewable_ids to array with reviewable id on success" do
+ result = described_class.new(reviewable, :success)
+
+ expect(result.remove_reviewable_ids).to eq([reviewable.id])
+ end
+
+ it "sets remove_reviewable_ids to empty array on failure" do
+ result = described_class.new(reviewable, :failure)
+
+ expect(result.remove_reviewable_ids).to eq([])
+ end
+ end
+end