From 3b32b6bc136d69bcfa94fafd0cf1d3fb7d9146dc Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 25 Jun 2021 09:15:17 +0800 Subject: [PATCH] DEV: Clean up state leak in `Site` tests. --- spec/models/site_spec.rb | 9 +++++---- spec/serializers/site_serializer_spec.rb | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 8ea6e9bb28b..3e2e0c2e81b 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -3,6 +3,9 @@ require 'rails_helper' describe Site do + after do + Site.clear_cache + end def expect_correct_themes(guardian) json = Site.json_for(guardian) @@ -63,10 +66,6 @@ describe Site do fab!(:user) { Fabricate(:user) } fab!(:guardian) { Guardian.new(user) } - after do - Site.clear_cache - end - it "omits read restricted categories" do expect(Site.new(guardian).categories.map(&:id)).to contain_exactly( SiteSetting.uncategorized_category_id, category.id @@ -136,6 +135,8 @@ describe Site do categories = Site.new(Guardian.new).categories expect(categories.last[:custom_fields]["enable_marketplace"]).to eq('f') + ensure + Site.preloaded_category_custom_fields.clear end end diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index 482905de36a..8dca84a7e04 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -26,6 +26,8 @@ describe SiteSerializer do c1 = serialized[:categories].find { |c| c[:id] == category.id } expect(c1[:custom_fields]["enable_marketplace"]).to eq("t") + ensure + Site.preloaded_category_custom_fields.clear end it "includes category tags" do