Allow the use of params[:name] when filtering labels
This commit is contained in:
parent
7c0ccbaac4
commit
af4d16d9b8
2 changed files with 22 additions and 3 deletions
|
@ -37,11 +37,14 @@ class LabelsFinder < UnionFinder
|
||||||
def with_title(items)
|
def with_title(items)
|
||||||
# Match no labels if an empty title is supplied to avoid matching all
|
# Match no labels if an empty title is supplied to avoid matching all
|
||||||
# labels (e.g. when an issue is moved)
|
# labels (e.g. when an issue is moved)
|
||||||
return Label.none if params[:title] && params[:title].empty?
|
return items.none if raw_title && raw_title.empty?
|
||||||
|
|
||||||
items = items.where(title: title) if title
|
if title
|
||||||
|
items = items.where(title: title)
|
||||||
|
else
|
||||||
items
|
items
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def group_id
|
def group_id
|
||||||
params[:group_id].presence
|
params[:group_id].presence
|
||||||
|
@ -59,6 +62,10 @@ class LabelsFinder < UnionFinder
|
||||||
params[:title].presence || params[:name].presence
|
params[:title].presence || params[:name].presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def raw_title
|
||||||
|
params[:title] || params[:name]
|
||||||
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
return @project if defined?(@project)
|
return @project if defined?(@project)
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,23 @@ describe LabelsFinder do
|
||||||
expect(finder.execute).to eq [group_label_2]
|
expect(finder.execute).to eq [group_label_2]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns label with title alias' do
|
||||||
|
finder = described_class.new(user, name: 'Group Label 2')
|
||||||
|
|
||||||
|
expect(finder.execute).to eq [group_label_2]
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns no labels if empty titles are supplied' do
|
it 'returns no labels if empty titles are supplied' do
|
||||||
finder = described_class.new(user, title: [])
|
finder = described_class.new(user, title: [])
|
||||||
|
|
||||||
expect(finder.execute).to be_empty
|
expect(finder.execute).to be_empty
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'returns no labels if empty names are supplied' do
|
||||||
|
finder = described_class.new(user, name: [])
|
||||||
|
|
||||||
|
expect(finder.execute).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue