Commit 29203198 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'osw-fix-missing-and-duplicated-milestones-on-list' into 'master'

Fix missing and duplicates on project milestone listing page

Closes #37078

See merge request gitlab-org/gitlab-ce!21058
parents e22effd4 ef66a4a5
...@@ -154,7 +154,7 @@ module Issuable ...@@ -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 ...@@ -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,6 +146,7 @@ class Milestone < ActiveRecord::Base ...@@ -146,6 +146,7 @@ class Milestone < ActiveRecord::Base
end end
def self.sort_by_attribute(method) def self.sort_by_attribute(method)
sorted =
case method.to_s case method.to_s
when 'due_date_asc' when 'due_date_asc'
reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC')) reorder(Gitlab::Database.nulls_last_order('due_date', 'ASC'))
...@@ -162,6 +163,8 @@ class Milestone < ActiveRecord::Base ...@@ -162,6 +163,8 @@ class Milestone < ActiveRecord::Base
else else
order_by(method) order_by(method)
end end
sorted.with_order_id_desc
end end
## ##
......
---
title: Fix missing and duplicates on project milestone listing page
merge_request: 21058
author:
type: fixed
...@@ -42,16 +42,45 @@ describe Projects::MilestonesController do ...@@ -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
......
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