summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeinrich Lee Yu <hleeyu@gmail.com>2018-10-26 10:47:14 +0800
committerHeinrich Lee Yu <hleeyu@gmail.com>2018-10-26 10:47:14 +0800
commite0f0c29b0cfe3c0c97191eeb96eae1299f3983d1 (patch)
treef5227f2614264fb1820ab1747579e11a5c9826c5
parentbf1ed85a9d6a932a99d0a5fdf70e72ea36c2600c (diff)
downloadgitlab-ce-e0f0c29b0cfe3c0c97191eeb96eae1299f3983d1.tar.gz
Support lowercase none / any
-rw-r--r--app/finders/issuable_finder.rb8
-rw-r--r--lib/api/helpers/custom_validators.rb2
-rw-r--r--spec/finders/issues_finder_spec.rb18
-rw-r--r--spec/lib/api/helpers/custom_validators_spec.rb2
4 files changed, 21 insertions, 9 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb
index ec4472de0c4..eb3d2498830 100644
--- a/app/finders/issuable_finder.rb
+++ b/app/finders/issuable_finder.rb
@@ -35,8 +35,8 @@ class IssuableFinder
requires_cross_project_access unless: -> { project? }
# This is used as a common filter for None / Any
- FILTER_NONE = 'None'.freeze
- FILTER_ANY = 'Any'.freeze
+ FILTER_NONE = 'none'.freeze
+ FILTER_ANY = 'any'.freeze
# This is accepted as a deprecated filter and is also used in unassigning users
NONE = '0'.freeze
@@ -250,11 +250,11 @@ class IssuableFinder
def filter_by_no_assignee?
# Assignee_id takes precedence over assignee_username
- [NONE, FILTER_NONE].include?(params[:assignee_id].to_s) || params[:assignee_username].to_s == NONE
+ [NONE, FILTER_NONE].include?(params[:assignee_id].to_s.downcase) || params[:assignee_username].to_s == NONE
end
def filter_by_any_assignee?
- params[:assignee_id].to_s == FILTER_ANY
+ params[:assignee_id].to_s.downcase == FILTER_ANY
end
# rubocop: disable CodeReuse/ActiveRecord
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb
index e4af75f1971..1058f4e8a5e 100644
--- a/lib/api/helpers/custom_validators.rb
+++ b/lib/api/helpers/custom_validators.rb
@@ -16,7 +16,7 @@ module API
value = params[attr_name]
return if value.is_a?(Integer) ||
- [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value)
+ [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase)
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
message: "should be an integer, 'None' or 'Any'"
diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb
index 7f4f613b406..2f164ffa8b0 100644
--- a/spec/finders/issues_finder_spec.rb
+++ b/spec/finders/issues_finder_spec.rb
@@ -57,17 +57,21 @@ describe IssuesFinder do
end
context 'filtering by no assignee' do
- let(:params) { { assignee_id: 0 } }
+ let(:params) { { assignee_id: 'None' } }
it 'returns issues not assigned to any assignee' do
expect(issues).to contain_exactly(issue4)
end
- end
- context 'filtering by no assignee' do
- let(:params) { { assignee_id: 'None' } }
+ it 'returns issues not assigned to any assignee' do
+ params[:assignee_id] = 0
+
+ expect(issues).to contain_exactly(issue4)
+ end
it 'returns issues not assigned to any assignee' do
+ params[:assignee_id] = 'none'
+
expect(issues).to contain_exactly(issue4)
end
end
@@ -78,6 +82,12 @@ describe IssuesFinder do
it 'returns issues assigned to any assignee' do
expect(issues).to contain_exactly(issue1, issue2, issue3)
end
+
+ it 'returns issues assigned to any assignee' do
+ params[:assignee_id] = 'any'
+
+ expect(issues).to contain_exactly(issue1, issue2, issue3)
+ end
end
context 'filtering by group_id' do
diff --git a/spec/lib/api/helpers/custom_validators_spec.rb b/spec/lib/api/helpers/custom_validators_spec.rb
index 810d05c479c..41e6fb47b11 100644
--- a/spec/lib/api/helpers/custom_validators_spec.rb
+++ b/spec/lib/api/helpers/custom_validators_spec.rb
@@ -38,6 +38,8 @@ describe API::Helpers::CustomValidators do
expect_no_validation_error({ 'test' => 100 })
expect_no_validation_error({ 'test' => 'None' })
expect_no_validation_error({ 'test' => 'Any' })
+ expect_no_validation_error({ 'test' => 'none' })
+ expect_no_validation_error({ 'test' => 'any' })
end
end