Skip to content

A platform for community discussion. Free, open, simple.

FIX: Category type registry causing flaky specs (#38853)

Martin Brennan380294e4feac
diff --git a/app/services/categories/type_registry.rb b/app/services/categories/type_registry.rb
index 736921d1ab4..7bf5637aac0 100644
--- a/app/services/categories/type_registry.rb
+++ b/app/services/categories/type_registry.rb
@@ -42,6 +42,10 @@ module Categories
def reset!
@types = nil
@owners = nil
+
+ # Always need to re-register the core Discussion type, the system doesn't work
+ # without it.
+ self.register(Categories::Types::Discussion)
end
# Returns all the category type counts in a hash with the type
diff --git a/spec/services/categories/type_registry_spec.rb b/spec/services/categories/type_registry_spec.rb
index c530dd854de..4680e2c7ae1 100644
--- a/spec/services/categories/type_registry_spec.rb
+++ b/spec/services/categories/type_registry_spec.rb
@@ -60,10 +60,10 @@ RSpec.describe Categories::TypeRegistry do
expect(queries.size).to eq(1)
end
- it "returns empty hash when no types are registered" do
+ it "returns only the core discussion type in the hash when no other types are registered" do
original_types = described_class.all.dup
described_class.reset!
- expect(described_class.counts).to eq({})
+ expect(described_class.counts).to eq({ discussion: 0 })
ensure
original_types&.each_value { |klass| described_class.register(klass) }
end