Commit dbbe474f authored by Sean McGivern's avatar Sean McGivern

Merge branch '49701-sorting-by-name-on-milestones-page-error' into 'master'

Resolve "Sorting by name on milestones page renders a 500 error"

Closes #49701

See merge request gitlab-org/gitlab-ce!20881
parents 3d2dad44 6c66a986
...@@ -149,6 +149,10 @@ class Milestone < ActiveRecord::Base ...@@ -149,6 +149,10 @@ class Milestone < ActiveRecord::Base
reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC')) reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC'))
when 'due_date_desc' when 'due_date_desc'
reorder(Gitlab::Database.nulls_last_order('due_date', 'DESC')) reorder(Gitlab::Database.nulls_last_order('due_date', 'DESC'))
when 'name_asc'
reorder(Arel::Nodes::Ascending.new(arel_table[:title].lower))
when 'name_desc'
reorder(Arel::Nodes::Descending.new(arel_table[:title].lower))
when 'start_date_asc' when 'start_date_asc'
reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC')) reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC'))
when 'start_date_desc' when 'start_date_desc'
......
---
title: Fix sorting by name on milestones page
merge_request: 20881
author:
type: fixed
...@@ -310,4 +310,24 @@ describe Milestone do ...@@ -310,4 +310,24 @@ describe Milestone do
expect(milestone.participants).to eq [user] expect(milestone.participants).to eq [user]
end end
end end
describe '.sort_by_attribute' do
set(:milestone_1) { create(:milestone, title: 'Foo') }
set(:milestone_2) { create(:milestone, title: 'Bar') }
set(:milestone_3) { create(:milestone, title: 'Zoo') }
context 'ordering by name ascending' do
it 'sorts by title ascending' do
expect(described_class.sort_by_attribute('name_asc'))
.to eq([milestone_2, milestone_1, milestone_3])
end
end
context 'ordering by name descending' do
it 'sorts by title descending' do
expect(described_class.sort_by_attribute('name_desc'))
.to eq([milestone_3, milestone_1, milestone_2])
end
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