From 4a2912233c2871e7607648fdf03dd4ae68c3dc67 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 11 May 2021 11:24:14 +1000 Subject: [PATCH] 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 https://github.com/discourse/discourse/blob/master/lib/topic_view.rb#L60 * FIX: convert to string for topic view custom filter --- lib/topic_view.rb | 2 +- spec/components/topic_view_spec.rb | 2 +- spec/requests/topics_controller_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index d56b064c06a..dcdec084bc7 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 9db72fd9f90..c4a104cd23e 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 68a010f6f16..cfb00692221 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