Return unique issues when using multiple labels

This ensures that IssuableFinder returns a collection of unique issues,
even when filtering issues using multiple labels.
This commit is contained in:
Yorick Peterse 2016-04-13 12:05:10 +02:00 committed by Jacob Schatz
parent 42e0625dfb
commit dc13f7c31d
2 changed files with 19 additions and 1 deletions

View file

@ -278,7 +278,9 @@ class IssuableFinder
end end
end end
items # When filtering by multiple labels we may end up duplicating issues (if one
# has multiple labels). This ensures we only return unique issues.
items.distinct
end end
def label_names def label_names

View file

@ -62,6 +62,22 @@ describe IssuesFinder do
expect(issues).to eq([issue2]) expect(issues).to eq([issue2])
end end
it 'returns unique issues when filtering by multiple labels' do
label2 = create(:label, project: project2)
create(:label_link, label: label2, target: issue2)
params = {
scope: 'all',
label_name: [label.title, label2.title].join(','),
state: 'opened'
}
issues = IssuesFinder.new(user, params).execute
expect(issues).to eq([issue2])
end
it 'should filter by no label name' do it 'should filter by no label name' do
params = { scope: "all", label_name: Label::None.title, state: 'opened' } params = { scope: "all", label_name: Label::None.title, state: 'opened' }
issues = IssuesFinder.new(user, params).execute issues = IssuesFinder.new(user, params).execute