Commit 281f3fcf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'dot-in-project-queries' into 'master'

Add a constraint on the query parameter to allow querying for projects with dots in their name.

See merge request !8210
parents 3608a1e8 322534aa
---
title: Allow API query to find projects with dots in their name
merge_request:
author: Bruno Melli
...@@ -159,7 +159,7 @@ module API ...@@ -159,7 +159,7 @@ module API
use :sort_params use :sort_params
use :pagination use :pagination
end end
get "/search/:query" do get "/search/:query", requirements: { query: /[^\/]+/ } do
search_service = Search::GlobalService.new(current_user, search: params[:query]).execute search_service = Search::GlobalService.new(current_user, search: params[:query]).execute
projects = search_service.objects('projects', params[:page]) projects = search_service.objects('projects', params[:page])
projects = projects.reorder(params[:order_by] => params[:sort]) projects = projects.reorder(params[:order_by] => params[:sort])
......
...@@ -1095,32 +1095,37 @@ describe API::Projects, api: true do ...@@ -1095,32 +1095,37 @@ describe API::Projects, api: true do
let!(:unfound_internal) { create(:empty_project, :internal, name: 'unfound internal') } let!(:unfound_internal) { create(:empty_project, :internal, name: 'unfound internal') }
let!(:public) { create(:empty_project, :public, name: "public #{query}") } let!(:public) { create(:empty_project, :public, name: "public #{query}") }
let!(:unfound_public) { create(:empty_project, :public, name: 'unfound public') } let!(:unfound_public) { create(:empty_project, :public, name: 'unfound public') }
let!(:one_dot_two) { create(:empty_project, :public, name: "one.dot.two") }
shared_examples_for 'project search response' do |args = {}| shared_examples_for 'project search response' do |args = {}|
it 'returns project search responses' do it 'returns project search responses' do
get api("/projects/search/#{query}", current_user) get api("/projects/search/#{args[:query]}", current_user)
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(args[:results]) expect(json_response.size).to eq(args[:results])
json_response.each { |project| expect(project['name']).to match(args[:match_regex] || /.*query.*/) } json_response.each { |project| expect(project['name']).to match(args[:match_regex] || /.*#{args[:query]}.*/) }
end end
end end
context 'when unauthenticated' do context 'when unauthenticated' do
it_behaves_like 'project search response', results: 1 do it_behaves_like 'project search response', query: 'query', results: 1 do
let(:current_user) { nil } let(:current_user) { nil }
end end
end end
context 'when authenticated' do context 'when authenticated' do
it_behaves_like 'project search response', results: 6 do it_behaves_like 'project search response', query: 'query', results: 6 do
let(:current_user) { user } let(:current_user) { user }
end end
it_behaves_like 'project search response', query: 'one.dot.two', results: 1 do
let(:current_user) { user }
end
end end
context 'when authenticated as a different user' do context 'when authenticated as a different user' do
it_behaves_like 'project search response', results: 2, match_regex: /(internal|public) query/ do it_behaves_like 'project search response', query: 'query', results: 2, match_regex: /(internal|public) query/ do
let(:current_user) { user2 } let(:current_user) { user2 }
end end
end end
......
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