FIX: flaky specs after topic view custom filters (#13019)

FIX: flaky specs after topic view custom filters (#13019)

  • FIX: flaky specs after topic view custom filters

When ensuring TopicView class variables return to the original state it should use empty Hash instead of empty Array. That

discourse/topic_view.rb at master · discourse/discourse · GitHub

  • FIX: convert to string for topic view custom filter
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index d56b064..dcdec08 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -781,7 +781,7 @@ class TopicView
       @contains_gaps = true
     end
 
-    if @filter.present? && @filter != 'summary' && TopicView.custom_filters[@filter].present?
+    if @filter.present? && @filter.to_s != 'summary' && TopicView.custom_filters[@filter].present?
       @filtered_posts = TopicView.custom_filters[@filter].call(@filtered_posts, self)
     end
 
diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb
index 9db72fd..c4a104c 100644
--- a/spec/components/topic_view_spec.rb
+++ b/spec/components/topic_view_spec.rb
@@ -74,7 +74,7 @@ describe TopicView do
       expect(tv.filter_posts).to eq([p0, p1])
 
       ensure
-        TopicView.instance_variable_set(:@custom_filters, [])
+        TopicView.instance_variable_set(:@custom_filters, {})
     end
   end
 
diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rb
index 68a010f..cfb0069 100644
--- a/spec/requests/topics_controller_spec.rb
+++ b/spec/requests/topics_controller_spec.rb
@@ -2456,7 +2456,7 @@ RSpec.describe TopicsController do
 
           expect(body["post_stream"]["posts"].map { |p| p["id"] }).to eq([post3.id])
         ensure
-          TopicView.instance_variable_set(:@custom_filters, [])
+          TopicView.instance_variable_set(:@custom_filters, {})
         end
       end
     end

GitHub sha: 4a291223

This commit appears in #13019 which was approved by SamSaffron. It was merged by SamSaffron.