summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2016-10-24 23:04:38 -0700
committerStan Hu <stanhu@gmail.com>2016-10-24 23:06:14 -0700
commit02f835c105df6c46d5c73468eedf1e2b0a0793b5 (patch)
tree769ff2e9ab3dbea79e6204fb774cd2c741d2299f
parentce256c28f2012a9c20fd1872fa91214b402528bf (diff)
downloadgitlab-ce-sh-fix-labels-move-issue.tar.gz
Improve readability and add specs for label filteringsh-fix-labels-move-issue
-rw-r--r--app/finders/labels_finder.rb13
-rw-r--r--spec/finders/labels_finder_spec.rb18
2 files changed, 21 insertions, 10 deletions
diff --git a/app/finders/labels_finder.rb b/app/finders/labels_finder.rb
index 8a85f7a2952..95e62cdb02a 100644
--- a/app/finders/labels_finder.rb
+++ b/app/finders/labels_finder.rb
@@ -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
diff --git a/spec/finders/labels_finder_spec.rb b/spec/finders/labels_finder_spec.rb
index eb8df8e2bb2..10cfb66ec1c 100644
--- a/spec/finders/labels_finder_spec.rb
+++ b/spec/finders/labels_finder_spec.rb
@@ -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