Commit 02f835c1 authored by Stan Hu's avatar Stan Hu

Improve readability and add specs for label filtering

parent ce256c28
......@@ -35,13 +35,10 @@ class LabelsFinder < UnionFinder
end
def with_title(items)
if title
items.where(title: title)
elsif params[:title] || params[:name] # empty input, should match nothing
items.none
else # not filtering
items
end
return items if title.nil?
return items.none if title.blank?
items.where(title: title)
end
def group_id
......@@ -57,7 +54,7 @@ class LabelsFinder < UnionFinder
end
def title
params[:title].presence || params[:name].presence
params[:title] || params[:name]
end
def project
......
......@@ -38,6 +38,14 @@ describe LabelsFinder do
expect(finder.execute).to eq [group_label_2, group_label_3, project_label_1, group_label_1, project_label_2, project_label_4]
end
it 'returns labels available if nil title is supplied' do
group_2.add_developer(user)
# params[:title] will return `nil` regardless whether it is specified
finder = described_class.new(user, title: nil)
expect(finder.execute).to eq [group_label_2, group_label_3, project_label_1, group_label_1, project_label_2, project_label_4]
end
end
context 'filtering by group_id' do
......@@ -71,13 +79,19 @@ describe LabelsFinder do
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 title is supplied' do
finder = described_class.new(user, title: [])
expect(finder.execute).to be_empty
end
it 'returns no labels if empty names are supplied' do
it 'returns no labels if blank title is supplied' do
finder = described_class.new(user, title: '')
expect(finder.execute).to be_empty
end
it 'returns no labels if empty name is supplied' do
finder = described_class.new(user, name: [])
expect(finder.execute).to be_empty
......
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