Commit 0139c221 authored by Robert Speicher's avatar Robert Speicher

Merge branch...

Merge branch '48339-sorting-by-name-on-explore-projects-page-renders-a-500-error-when-logged-in' into 'master'

Resolve "Sorting by name on explore projects page renders a 500 error when logged in"

Closes #48339

See merge request gitlab-org/gitlab-ce!20162
parents 7d62da69 b9b2060d
...@@ -12,8 +12,8 @@ module Sortable ...@@ -12,8 +12,8 @@ module Sortable
scope :order_created_asc, -> { reorder(created_at: :asc) } scope :order_created_asc, -> { reorder(created_at: :asc) }
scope :order_updated_desc, -> { reorder(updated_at: :desc) } scope :order_updated_desc, -> { reorder(updated_at: :desc) }
scope :order_updated_asc, -> { reorder(updated_at: :asc) } scope :order_updated_asc, -> { reorder(updated_at: :asc) }
scope :order_name_asc, -> { reorder("lower(name) asc") } scope :order_name_asc, -> { reorder(Arel::Nodes::Ascending.new(arel_table[:name].lower)) }
scope :order_name_desc, -> { reorder("lower(name) desc") } scope :order_name_desc, -> { reorder(Arel::Nodes::Descending.new(arel_table[:name].lower)) }
end end
module ClassMethods module ClassMethods
......
---
title: Fix sorting by name on explore projects page
merge_request: 20162
author:
type: fixed
...@@ -40,15 +40,25 @@ describe Sortable do ...@@ -40,15 +40,25 @@ describe Sortable do
describe 'ordering by name' do describe 'ordering by name' do
it 'ascending' do it 'ascending' do
expect(relation).to receive(:reorder).with("lower(name) asc") expect(relation).to receive(:reorder).once.and_call_original
relation.order_by('name_asc') table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces))
column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name))
sql = relation.order_by('name_asc').to_sql
expect(sql).to match /.+ORDER BY LOWER\(#{table}.#{column}\) ASC\z/
end end
it 'descending' do it 'descending' do
expect(relation).to receive(:reorder).with("lower(name) desc") expect(relation).to receive(:reorder).once.and_call_original
table = Regexp.escape(ActiveRecord::Base.connection.quote_table_name(:namespaces))
column = Regexp.escape(ActiveRecord::Base.connection.quote_column_name(:name))
sql = relation.order_by('name_desc').to_sql
relation.order_by('name_desc') expect(sql).to match /.+ORDER BY LOWER\(#{table}.#{column}\) DESC\z/
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment