From ee89c68687a7d0ffd5a2454f1b98210eb7f7a607 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 14 Jul 2022 08:54:31 +0800 Subject: [PATCH] DEV: Unify way to reset Site.preloaded_category_custom_fields (#17384) --- app/models/site.rb | 6 +++++- spec/models/site_spec.rb | 2 +- spec/requests/api/site_spec.rb | 2 +- spec/serializers/site_serializer_spec.rb | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index 8b6df669974..f04b25bd766 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -5,7 +5,11 @@ class Site include ActiveModel::Serialization cattr_accessor :preloaded_category_custom_fields - self.preloaded_category_custom_fields = Set.new + + def self.reset_preloaded_category_custom_fields + self.preloaded_category_custom_fields = Set.new + end + reset_preloaded_category_custom_fields ## # Sometimes plugins need to have additional data or options available diff --git a/spec/models/site_spec.rb b/spec/models/site_spec.rb index 213fa774cd6..1cfeac59dc8 100644 --- a/spec/models/site_spec.rb +++ b/spec/models/site_spec.rb @@ -133,7 +133,7 @@ describe Site do expect(categories.last[:custom_fields]["enable_marketplace"]).to eq('f') ensure - Site.preloaded_category_custom_fields.clear + Site.reset_preloaded_category_custom_fields end it 'sets the can_edit field for categories correctly' do diff --git a/spec/requests/api/site_spec.rb b/spec/requests/api/site_spec.rb index 9d026b5dfbb..ec513be52d9 100644 --- a/spec/requests/api/site_spec.rb +++ b/spec/requests/api/site_spec.rb @@ -34,7 +34,7 @@ describe 'site' do let(:expected_request_schema) { expected_request_schema } end ensure - Site.preloaded_category_custom_fields = Set.new + Site.reset_preloaded_category_custom_fields end end end diff --git a/spec/serializers/site_serializer_spec.rb b/spec/serializers/site_serializer_spec.rb index 6ee0d5968ec..6db717a38eb 100644 --- a/spec/serializers/site_serializer_spec.rb +++ b/spec/serializers/site_serializer_spec.rb @@ -25,7 +25,7 @@ describe SiteSerializer do expect(c1[:custom_fields]["enable_marketplace"]).to eq("t") ensure - Site.preloaded_category_custom_fields.clear + Site.reset_preloaded_category_custom_fields end it "includes category tags" do