Skip to content

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

DEV: Fix flaky test due to a lack of deterministic ordering (#20087)

Alan Guo Xiang Tanc5c72a74b726
diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index 2e939db5afd..6f9025414b4 100644
--- a/app/controllers/tags_controller.rb
+++ b/app/controllers/tags_controller.rb
@@ -63,10 +63,13 @@ class TagsController < ::ApplicationController
unrestricted_tags = DiscourseTagging.filter_visible(tags.where(target_tag_id: nil), guardian)
categories =
- Category.where(
- "id IN (SELECT category_id FROM category_tags WHERE category_id IN (?))",
- guardian.allowed_category_ids,
- ).includes(:none_synonym_tags)
+ Category
+ .where(
+ "id IN (SELECT category_id FROM category_tags WHERE category_id IN (?))",
+ guardian.allowed_category_ids,
+ )
+ .includes(:none_synonym_tags)
+ .order(:id)
category_tag_counts =
categories
diff --git a/spec/requests/tags_controller_spec.rb b/spec/requests/tags_controller_spec.rb
index e4c64271e44..e3622bdaeae 100644
--- a/spec/requests/tags_controller_spec.rb
+++ b/spec/requests/tags_controller_spec.rb
@@ -197,7 +197,7 @@ RSpec.describe TagsController do
expect(categories[0]["tags"][0]["target_tag"]).to eq(nil)
end
- xit "does not result in N+1 queries when there are multiple categories configured with tags for an admin user" do
+ it "does not result in N+1 queries when there are multiple categories configured with tags for an admin user" do
category.update!(tags: [test_tag])
sign_in(admin)