Fix missing and duplicates on project milestone listing page
This commit is contained in:
parent
415b2f943b
commit
ef66a4a57c
|
@ -154,7 +154,7 @@ module Issuable
|
||||||
end
|
end
|
||||||
|
|
||||||
# Break ties with the ID column for pagination
|
# Break ties with the ID column for pagination
|
||||||
sorted.order(id: :desc)
|
sorted.with_order_id_desc
|
||||||
end
|
end
|
||||||
|
|
||||||
def order_due_date_and_labels_priority(excluded_labels: [])
|
def order_due_date_and_labels_priority(excluded_labels: [])
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Sortable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
scope :with_order_id_desc, -> { order(id: :desc) }
|
||||||
scope :order_id_desc, -> { reorder(id: :desc) }
|
scope :order_id_desc, -> { reorder(id: :desc) }
|
||||||
scope :order_id_asc, -> { reorder(id: :asc) }
|
scope :order_id_asc, -> { reorder(id: :asc) }
|
||||||
scope :order_created_desc, -> { reorder(created_at: :desc) }
|
scope :order_created_desc, -> { reorder(created_at: :desc) }
|
||||||
|
|
|
@ -146,22 +146,25 @@ class Milestone < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sort_by_attribute(method)
|
def self.sort_by_attribute(method)
|
||||||
case method.to_s
|
sorted =
|
||||||
when 'due_date_asc'
|
case method.to_s
|
||||||
reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC'))
|
when 'due_date_asc'
|
||||||
when 'due_date_desc'
|
reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC'))
|
||||||
reorder(Gitlab::Database.nulls_last_order('due_date', 'DESC'))
|
when 'due_date_desc'
|
||||||
when 'name_asc'
|
reorder(Gitlab::Database.nulls_last_order('due_date', 'DESC'))
|
||||||
reorder(Arel::Nodes::Ascending.new(arel_table[:title].lower))
|
when 'name_asc'
|
||||||
when 'name_desc'
|
reorder(Arel::Nodes::Ascending.new(arel_table[:title].lower))
|
||||||
reorder(Arel::Nodes::Descending.new(arel_table[:title].lower))
|
when 'name_desc'
|
||||||
when 'start_date_asc'
|
reorder(Arel::Nodes::Descending.new(arel_table[:title].lower))
|
||||||
reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC'))
|
when 'start_date_asc'
|
||||||
when 'start_date_desc'
|
reorder(Gitlab::Database.nulls_last_order('start_date', 'ASC'))
|
||||||
reorder(Gitlab::Database.nulls_last_order('start_date', 'DESC'))
|
when 'start_date_desc'
|
||||||
else
|
reorder(Gitlab::Database.nulls_last_order('start_date', 'DESC'))
|
||||||
order_by(method)
|
else
|
||||||
end
|
order_by(method)
|
||||||
|
end
|
||||||
|
|
||||||
|
sorted.with_order_id_desc
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix missing and duplicates on project milestone listing page
|
||||||
|
merge_request: 21058
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -42,16 +42,45 @@ describe Projects::MilestonesController do
|
||||||
|
|
||||||
describe "#index" do
|
describe "#index" do
|
||||||
context "as html" do
|
context "as html" do
|
||||||
before do
|
def render_index(project:, page:)
|
||||||
get :index, namespace_id: project.namespace.id, project_id: project.id
|
get :index, namespace_id: project.namespace.id,
|
||||||
|
project_id: project.id,
|
||||||
|
page: page
|
||||||
end
|
end
|
||||||
|
|
||||||
it "queries only projects milestones" do
|
it "queries only projects milestones" do
|
||||||
|
render_index project: project, page: 1
|
||||||
|
|
||||||
milestones = assigns(:milestones)
|
milestones = assigns(:milestones)
|
||||||
|
|
||||||
expect(milestones.count).to eq(1)
|
expect(milestones.count).to eq(1)
|
||||||
expect(milestones.where(project_id: nil)).to be_empty
|
expect(milestones.where(project_id: nil)).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'renders paginated milestones without missing or duplicates' do
|
||||||
|
allow(Milestone).to receive(:default_per_page).and_return(2)
|
||||||
|
create_list(:milestone, 5, project: project)
|
||||||
|
|
||||||
|
render_index project: project, page: 1
|
||||||
|
page_1_milestones = assigns(:milestones)
|
||||||
|
expect(page_1_milestones.size).to eq(2)
|
||||||
|
|
||||||
|
render_index project: project, page: 2
|
||||||
|
page_2_milestones = assigns(:milestones)
|
||||||
|
expect(page_2_milestones.size).to eq(2)
|
||||||
|
|
||||||
|
render_index project: project, page: 3
|
||||||
|
page_3_milestones = assigns(:milestones)
|
||||||
|
expect(page_3_milestones.size).to eq(2)
|
||||||
|
|
||||||
|
rendered_milestone_ids =
|
||||||
|
page_1_milestones.pluck(:id) +
|
||||||
|
page_2_milestones.pluck(:id) +
|
||||||
|
page_3_milestones.pluck(:id)
|
||||||
|
|
||||||
|
expect(rendered_milestone_ids)
|
||||||
|
.to match_array(project.milestones.pluck(:id))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "as json" do
|
context "as json" do
|
||||||
|
|
Loading…
Reference in New Issue