List issues with another milestone that has a matching board list label

parent 90696194
......@@ -51,10 +51,14 @@ module Boards
def without_board_labels(issues)
return issues unless board_label_ids.any?
issues.where.not(
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where(label_id: board_label_ids).limit(1).arel.exists
)
label_links = LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where(label_id: board_label_ids)
if board.milestone.present?
label_links = label_links.where("issues.milestone_id = ?", board.milestone_id)
end
issues.where.not(label_links.limit(1).arel.exists)
end
def with_list_label(issues)
......
......@@ -6,6 +6,9 @@ describe Boards::Issues::ListService, services: true do
let(:project) { create(:empty_project) }
let(:board) { create(:board, project: project) }
let(:m1) { create(:milestone, project: project) }
let(:m2) { create(:milestone, project: project) }
let(:bug) { create(:label, project: project, name: 'Bug') }
let(:development) { create(:label, project: project, name: 'Development') }
let(:testing) { create(:label, project: project, name: 'Testing') }
......@@ -17,14 +20,14 @@ describe Boards::Issues::ListService, services: true do
let!(:list2) { create(:list, board: board, label: testing, position: 1) }
let!(:done) { board.done_list }
let!(:opened_issue1) { create(:labeled_issue, project: project, labels: [bug]) }
let!(:opened_issue2) { create(:labeled_issue, project: project, labels: [p2]) }
let!(:reopened_issue1) { create(:issue, :reopened, project: project) }
let!(:opened_issue1) { create(:labeled_issue, project: project, milestone: m1, title: 'Issue 1', labels: [bug]) }
let!(:opened_issue2) { create(:labeled_issue, project: project, milestone: m2, title: 'Issue 2', labels: [p2]) }
let!(:reopened_issue1) { create(:issue, :reopened, project: project, title: 'Issue 3', ) }
let!(:list1_issue1) { create(:labeled_issue, project: project, labels: [p2, development]) }
let!(:list1_issue2) { create(:labeled_issue, project: project, labels: [development]) }
let!(:list1_issue3) { create(:labeled_issue, project: project, labels: [development, p1]) }
let!(:list2_issue1) { create(:labeled_issue, project: project, labels: [testing]) }
let!(:list1_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [p2, development]) }
let!(:list1_issue2) { create(:labeled_issue, project: project, milestone: m2, labels: [development]) }
let!(:list1_issue3) { create(:labeled_issue, project: project, milestone: m1, labels: [development, p1]) }
let!(:list2_issue1) { create(:labeled_issue, project: project, milestone: m1, labels: [testing]) }
let!(:closed_issue1) { create(:labeled_issue, :closed, project: project, labels: [bug]) }
let!(:closed_issue2) { create(:labeled_issue, :closed, project: project, labels: [p3]) }
......@@ -43,30 +46,43 @@ describe Boards::Issues::ListService, services: true do
described_class.new(project, user, params).execute
end
context 'issues are ordered by priority' do
it 'returns opened issues when list_id is missing' do
params = { board_id: board.id }
context 'when list_id is missing' do
context 'when board does not have a milestone' do
it 'returns opened issues without board labels applied' do
params = { board_id: board.id }
issues = described_class.new(project, user, params).execute
issues = described_class.new(project, user, params).execute
expect(issues).to eq [opened_issue2, reopened_issue1, opened_issue1]
expect(issues).to eq [opened_issue2, reopened_issue1, opened_issue1]
end
end
it 'returns closed issues when listing issues from Done' do
params = { board_id: board.id, id: done.id }
context 'when board have a milestone' do
it 'returns opened issues without board labels and milestone applied' do
params = { board_id: board.id }
board.update_attribute(:milestone, m1)
issues = described_class.new(project, user, params).execute
issues = described_class.new(project, user, params).execute
expect(issues).to eq [closed_issue4, closed_issue2, closed_issue3, closed_issue1]
expect(issues).to eq [opened_issue2, list1_issue2, reopened_issue1, opened_issue1]
end
end
end
it 'returns opened issues that have label list applied when listing issues from a label list' do
params = { board_id: board.id, id: list1.id }
it 'returns closed issues when listing issues from Done' do
params = { board_id: board.id, id: done.id }
issues = described_class.new(project, user, params).execute
issues = described_class.new(project, user, params).execute
expect(issues).to eq [list1_issue3, list1_issue1, list1_issue2]
end
expect(issues).to eq [closed_issue4, closed_issue2, closed_issue3, closed_issue1]
end
it 'returns opened issues that have label list applied when listing issues from a label list' do
params = { board_id: board.id, id: list1.id }
issues = described_class.new(project, user, params).execute
expect(issues).to eq [list1_issue3, list1_issue1, list1_issue2]
end
context 'with list that does not belong to the board' 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