Fix issues/MRs filter when ordering by milestone due date
This commit is contained in:
parent
baa9c66057
commit
996240a489
3 changed files with 45 additions and 4 deletions
|
@ -253,9 +253,9 @@ class IssuableFinder
|
|||
items = items.where(milestone_id: [-1, nil])
|
||||
elsif filter_by_upcoming_milestone?
|
||||
upcoming_ids = Milestone.upcoming_ids_by_projects(projects)
|
||||
items = items.joins(:milestone).where(milestone_id: upcoming_ids)
|
||||
items = items.left_joins_milestones.where(milestone_id: upcoming_ids)
|
||||
else
|
||||
items = items.joins(:milestone).where(milestones: { title: params[:milestone_title] })
|
||||
items = items.left_joins_milestones.where(milestones: { title: params[:milestone_title] })
|
||||
|
||||
if projects
|
||||
items = items.where(milestones: { project_id: projects })
|
||||
|
|
|
@ -35,10 +35,12 @@ module Issuable
|
|||
scope :only_opened, -> { with_state(:opened) }
|
||||
scope :only_reopened, -> { with_state(:reopened) }
|
||||
scope :closed, -> { with_state(:closed) }
|
||||
|
||||
scope :left_joins_milestones, -> { joins("LEFT OUTER JOIN milestones ON #{table_name}.milestone_id = milestones.id") }
|
||||
scope :order_milestone_due_desc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date DESC, milestones.id DESC') }
|
||||
scope :order_milestone_due_asc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date ASC, milestones.id ASC') }
|
||||
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
|
||||
|
||||
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
|
||||
scope :join_project, -> { joins(:project) }
|
||||
scope :references_project, -> { references(:project) }
|
||||
scope :non_archived, -> { join_project.where(projects: { archived: false }) }
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Issue, "Issuable" do
|
||||
let(:issue) { create(:issue) }
|
||||
let!(:issue) { create(:issue) }
|
||||
let(:user) { create(:user) }
|
||||
|
||||
describe "Associations" do
|
||||
|
@ -114,6 +114,45 @@ describe Issue, "Issuable" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#sort" do
|
||||
#Correct order is:
|
||||
#Issues/MRs with milestones ordered by date
|
||||
#Issues/MRs with milestones without dates
|
||||
#Issues/MRs without milestones
|
||||
let(:project) { issue.project }
|
||||
let!(:early_milestone) { create(:milestone, project: project, due_date: 10.days.from_now) }
|
||||
let!(:late_milestone) { create(:milestone, project: project, due_date: 30.days.from_now) }
|
||||
let!(:issue1) { create(:issue, project: project, milestone: early_milestone) }
|
||||
let!(:issue2) { create(:issue, project: project, milestone: late_milestone) }
|
||||
let!(:issue3) { create(:issue, project: project) }
|
||||
|
||||
|
||||
context "milestone due later" do
|
||||
subject { Issue.where(project_id: project.id).order_milestone_due_desc }
|
||||
before { @issues = subject }
|
||||
|
||||
it "puts issues with nil values at the end of collection" do
|
||||
expect(@issues.first).to eq(issue2)
|
||||
expect(@issues.second).to eq(issue1)
|
||||
expect(@issues.third).to eq(issue)
|
||||
expect(@issues.fourth).to eq(issue3)
|
||||
end
|
||||
end
|
||||
|
||||
context "milestone due soon" do
|
||||
subject { Issue.where(project_id: project.id).order_milestone_due_asc }
|
||||
before { @issues = subject }
|
||||
|
||||
it "puts issues with nil values at the end of collection" do
|
||||
expect(@issues.first).to eq(issue1)
|
||||
expect(@issues.second).to eq(issue2)
|
||||
expect(@issues.third).to eq(issue)
|
||||
expect(@issues.fourth).to eq(issue3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe '#subscribed?' do
|
||||
context 'user is not a participant in the issue' do
|
||||
before { allow(issue).to receive(:participants).with(user).and_return([]) }
|
||||
|
|
Loading…
Reference in a new issue