Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Respect default category sort order when navigating within app #23270

Merged
merged 1 commit into from Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/topic_query.rb
Expand Up @@ -749,7 +749,7 @@ def default_results(options = {})
# category default sort order
sort_order, sort_ascending =
Category.where(id: category_id).pick(:sort_order, :sort_ascending)
if sort_order && (filter.blank? || %i[latest unseen].include?(filter))
if sort_order && (filter.blank? || %w[latest unseen].include?(filter.to_s))
options[:order] = sort_order
options[:ascending] = !!sort_ascending ? "true" : "false"
else
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/topic_query_spec.rb
Expand Up @@ -998,6 +998,13 @@ class ::TopicQuery
expect(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 is passed as a string" do
category.update!(sort_order: "created", sort_ascending: true)
topic_ids =
TopicQuery.new(user, category: category.id, filter: "latest").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" do
category.update!(sort_order: "created", sort_ascending: true)

Expand Down