DEV: cleanup custom filters to prevent leaks

Ensures we clean up any custom filters added in the specs to prevent any leaks when running the specs.

Follow up to https://github.com/discourse/discourse/pull/26770#discussion_r1582464760
This commit is contained in:
Régis Hanol
2024-04-29 15:56:52 +02:00
parent 271ca2c968
commit f7a1272fa4
7 changed files with 22 additions and 13 deletions

View File

@ -3336,6 +3336,9 @@ RSpec.describe TopicsController do
describe "custom filters" do
fab!(:post2) { Fabricate(:post, user: post_author2, topic: topic, percent_rank: 0.2) }
fab!(:post3) { Fabricate(:post, user: post_author3, topic: topic, percent_rank: 0.5) }
after { TopicView.custom_filters.clear }
it "should return the right posts" do
TopicView.add_custom_filter("percent") do |posts, topic_view|
posts.where(percent_rank: 0.5)
@ -3348,8 +3351,6 @@ RSpec.describe TopicsController do
body = response.parsed_body
expect(body["post_stream"]["posts"].map { |p| p["id"] }).to eq([post3.id])
ensure
TopicView.instance_variable_set(:@custom_filters, {})
end
end
end