A platform for community discussion. Free, open, simple.
FIX: Respect default category sort when `filter=default` (#23411)
David Taylor534f62cf5b67
diff --git a/lib/topic_query.rb b/lib/topic_query.rbindex a8c3610650c..37655e4186c 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -749,7 +749,7 @@ class TopicQuery# category default sort ordersort_order, sort_ascending =Category.where(id: category_id).pick(:sort_order, :sort_ascending)- if sort_order && (filter.blank? || %w[latest unseen].include?(filter.to_s))+ if sort_order && (filter.blank? || %w[default latest unseen].include?(filter.to_s))options[:order] = sort_orderoptions[:ascending] = !!sort_ascending ? "true" : "false"elsediff --git a/spec/lib/topic_query_spec.rb b/spec/lib/topic_query_spec.rbindex b7a14f0f732..19aa429af2f 100644--- a/spec/lib/topic_query_spec.rb+++ b/spec/lib/topic_query_spec.rb@@ -1005,6 +1005,17 @@ RSpec.describe TopicQuery doexpect(topic_ids - [topic_category.id]).to eq([topic_in_cat1.id, topic_in_cat2.id])end+ it "uses the category's default sort order when filter=default is passed explicitly" do+ category.update!(sort_order: "created", sort_ascending: true)+ topic_ids =+ TopicQuery+ .new(user, category: category.id, filter: "default")+ .list_latest+ .topics+ .map(&:id)+ expect(topic_ids - [topic_category.id]).to eq([topic_in_cat1.id, topic_in_cat2.id])+ end+it "should apply default sort order to latest and unseen filters only" docategory.update!(sort_order: "created", sort_ascending: true)