From b33d38206966d962417dbc793ac2f105ef4b73f4 Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 18 Nov 2022 15:05:03 +0000 Subject: [PATCH] Order BatchTaggableTagsQuery by name for consistency and to avoid flakey test failure --- app/queries/batch_taggable_tags_query.rb | 6 ++---- spec/queries/batch_taggable_tags_query_spec.rb | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/queries/batch_taggable_tags_query.rb b/app/queries/batch_taggable_tags_query.rb index c8f28ad415..ea9f6d9bc5 100644 --- a/app/queries/batch_taggable_tags_query.rb +++ b/app/queries/batch_taggable_tags_query.rb @@ -2,7 +2,7 @@ class BatchTaggableTagsQuery def self.call(taggables) - tags = ::ActsAsTaggableOn::Tag. + ::ActsAsTaggableOn::Tag. joins(:taggings). includes(:taggings). where(taggings: @@ -10,9 +10,7 @@ class BatchTaggableTagsQuery taggable_type: taggables.model.to_s, taggable_id: taggables, context: 'tags' - }) - - tags.each_with_object({}) do |tag, indexed_hash| + }).order("tags.name").each_with_object({}) do |tag, indexed_hash| tag.taggings.each do |tagging| indexed_hash[tagging.taggable_id] ||= [] indexed_hash[tagging.taggable_id] << tag.name diff --git a/spec/queries/batch_taggable_tags_query_spec.rb b/spec/queries/batch_taggable_tags_query_spec.rb index 771f7aac38..2bb63926ea 100644 --- a/spec/queries/batch_taggable_tags_query_spec.rb +++ b/spec/queries/batch_taggable_tags_query_spec.rb @@ -13,7 +13,7 @@ describe BatchTaggableTagsQuery do ) expect(tags).to eq( { - customer_i.id => ["volunteer", "member"], + customer_i.id => ["member", "volunteer"], customer_ii.id => ["member"], } )