Fix ordering by name on milestones page
We should sort by title because name is only an alias for the title attribute on the milestone model.
This commit is contained in:
parent
3d2dad449d
commit
16c8a030fc
2 changed files with 24 additions and 0 deletions
|
@ -149,6 +149,10 @@ class Milestone < ActiveRecord::Base
|
|||
reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC'))
|
||||
when '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'
|
||||
reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC'))
|
||||
when 'start_date_desc'
|
||||
|
|
|
@ -310,4 +310,24 @@ describe Milestone do
|
|||
expect(milestone.participants).to eq [user]
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue