File tree 7 files changed +47
-2
lines changed
7 files changed +47
-2
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,8 @@ def filter(filter_name)
318
318
#
319
319
# Returns an ActiveRecord::Relation.
320
320
def search ( query )
321
+ return none if query . blank?
322
+
321
323
query = query . downcase
322
324
323
325
order = <<~SQL
@@ -341,6 +343,8 @@ def search(query)
341
343
# This method uses ILIKE on PostgreSQL and LIKE on MySQL.
342
344
343
345
def search_with_secondary_emails ( query )
346
+ return none if query . blank?
347
+
344
348
query = query . downcase
345
349
346
350
email_table = Email . arel_table
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Fix error on empty query for Members API
3
+ merge_request : 16235
4
+ author :
5
+ type : fixed
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class Members < Grape::API
22
22
source = find_source ( source_type , params [ :id ] )
23
23
24
24
users = source . users
25
- users = users . merge ( User . search ( params [ :query ] ) ) if params [ :query ]
25
+ users = users . merge ( User . search ( params [ :query ] ) ) if params [ :query ] . present?
26
26
27
27
present paginate ( users ) , with : Entities ::Member , source : source
28
28
end
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ class Members < Grape::API
23
23
source = find_source ( source_type , params [ :id ] )
24
24
25
25
users = source . users
26
- users = users . merge ( User . search ( params [ :query ] ) ) if params [ :query ]
26
+ users = users . merge ( User . search ( params [ :query ] ) ) if params [ :query ] . present?
27
27
28
28
present paginate ( users ) , with : ::API ::Entities ::Member , source : source
29
29
end
Original file line number Diff line number Diff line change 966
966
expect ( described_class . search ( user3 . username . upcase ) ) . to eq ( [ user3 ] )
967
967
end
968
968
end
969
+
970
+ it 'returns no matches for an empty string' do
971
+ expect ( described_class . search ( '' ) ) . to be_empty
972
+ end
973
+
974
+ it 'returns no matches for nil' do
975
+ expect ( described_class . search ( nil ) ) . to be_empty
976
+ end
969
977
end
970
978
971
979
describe '.search_with_secondary_emails' do
1020
1028
it 'does not return users with a matching part of secondary email' do
1021
1029
expect ( search_with_secondary_emails ( email . email [ 1 ..4 ] ) ) . not_to include ( [ email . user ] )
1022
1030
end
1031
+
1032
+ it 'returns no matches for an empty string' do
1033
+ expect ( search_with_secondary_emails ( '' ) ) . to be_empty
1034
+ end
1035
+
1036
+ it 'returns no matches for nil' do
1037
+ expect ( search_with_secondary_emails ( nil ) ) . to be_empty
1038
+ end
1023
1039
end
1024
1040
1025
1041
describe '.find_by_ssh_key_id' do
Original file line number Diff line number Diff line change 65
65
expect ( json_response . count ) . to eq ( 1 )
66
66
expect ( json_response . first [ 'username' ] ) . to eq ( master . username )
67
67
end
68
+
69
+ it 'finds all members with no query specified' do
70
+ get api ( "/#{ source_type . pluralize } /#{ source . id } /members" , developer ) , query : ''
71
+
72
+ expect ( response ) . to have_gitlab_http_status ( 200 )
73
+ expect ( response ) . to include_pagination_headers
74
+ expect ( json_response ) . to be_an Array
75
+ expect ( json_response . count ) . to eq ( 2 )
76
+ expect ( json_response . map { |u | u [ 'id' ] } ) . to match_array [ master . id , developer . id ]
77
+ end
68
78
end
69
79
end
70
80
Original file line number Diff line number Diff line change 58
58
expect ( json_response . count ) . to eq ( 1 )
59
59
expect ( json_response . first [ 'username' ] ) . to eq ( master . username )
60
60
end
61
+
62
+ it 'finds all members with no query specified' do
63
+ get v3_api ( "/#{ source_type . pluralize } /#{ source . id } /members" , developer ) , query : ''
64
+
65
+ expect ( response ) . to have_gitlab_http_status ( 200 )
66
+ expect ( response ) . to include_pagination_headers
67
+ expect ( json_response ) . to be_an Array
68
+ expect ( json_response . count ) . to eq ( 2 )
69
+ expect ( json_response . map { |u | u [ 'id' ] } ) . to match_array [ master . id , developer . id ]
70
+ end
61
71
end
62
72
end
63
73
You can’t perform that action at this time.
0 commit comments