Fix sorting by name on explore projects page

parent 45453c27
......@@ -12,8 +12,8 @@ module Sortable
scope :order_created_asc, -> { reorder(created_at: :asc) }
scope :order_updated_desc, -> { reorder(updated_at: :desc) }
scope :order_updated_asc, -> { reorder(updated_at: :asc) }
scope :order_name_asc, -> { reorder("lower(name) asc") }
scope :order_name_desc, -> { reorder("lower(name) desc") }
scope :order_name_asc, -> { reorder(Arel::Nodes::Ascending.new(arel_table[:name].lower)) }
scope :order_name_desc, -> { reorder(Arel::Nodes::Descending.new(arel_table[:name].lower)) }
end
module ClassMethods
......
......@@ -40,15 +40,25 @@ describe Sortable do
describe 'ordering by name' 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
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
......
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