From 81c2d38cea7c805cca4dfc7f4245506554991f12 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 20 Oct 2023 08:18:49 +0800 Subject: [PATCH] DEV: Fix flaky tests due to the lack of ordering (#23910) Why this change? The following test was flaky due to the lack of ordering in `SiteSerializer#anonymous_default_navigation_menu_tags` when fetching the tags. ``` 1) SiteSerializer#anonymous_default_navigation_menu_tags includes only tags user can see in the serialised object when user is anonymous Failure/Error: expect(serialized[:anonymous_default_navigation_menu_tags]).to eq( [ { name: "dev", description: "some description", pm_only: false }, { name: "random", description: tag2.description, pm_only: false }, ], ) ``` What does this change do? Add ordering by name when fetching tags in `SiteSerializer#anonymous_default_navigation_menu_tags` --- app/serializers/site_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/serializers/site_serializer.rb b/app/serializers/site_serializer.rb index 06fe0478d03..9bbe67f4271 100644 --- a/app/serializers/site_serializer.rb +++ b/app/serializers/site_serializer.rb @@ -278,7 +278,7 @@ class SiteSerializer < ApplicationSerializer SiteSetting.default_navigation_menu_tags.split("|") - DiscourseTagging.hidden_tag_names(scope) - serialize_tags(Tag.where(name: tag_names)) + serialize_tags(Tag.where(name: tag_names).order(:name)) end end