diff options
Diffstat (limited to 'spec/requests/api/projects_spec.rb')
-rw-r--r-- | spec/requests/api/projects_spec.rb | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 7248908b494..cfa7a1a31a3 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -21,7 +21,7 @@ describe API::Projects do let(:project) { create(:project, :repository, namespace: user.namespace) } let(:project2) { create(:project, namespace: user.namespace) } let(:project_member) { create(:project_member, :developer, user: user3, project: project) } - let(:user4) { create(:user) } + let(:user4) { create(:user, username: 'user.with.dot') } let(:project3) do create(:project, :private, @@ -49,6 +49,27 @@ describe API::Projects do namespace: user4.namespace) end + shared_context 'with language detection' do + let(:ruby) { create(:programming_language, name: 'Ruby') } + let(:javascript) { create(:programming_language, name: 'JavaScript') } + let(:html) { create(:programming_language, name: 'HTML') } + + let(:mock_repo_languages) do + { + project => { ruby => 0.5, html => 0.5 }, + project3 => { html => 0.7, javascript => 0.3 } + } + end + + before do + mock_repo_languages.each do |proj, lang_shares| + lang_shares.each do |lang, share| + create(:repository_language, project: proj, programming_language: lang, share: share) + end + end + end + end + describe 'GET /projects' do shared_examples_for 'projects response' do it 'returns an array of projects' do @@ -344,6 +365,19 @@ describe API::Projects do end end + context 'and using the programming language filter' do + include_context 'with language detection' + + it 'filters case-insensitively by programming language' do + get api('/projects', user), params: { with_programming_language: 'javascript' } + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |p| p['id'] }).to contain_exactly(project3.id) + end + end + context 'and using sorting' do it 'returns the correct order when sorted by id' do get api('/projects', user), params: { order_by: 'id', sort: 'desc' } @@ -724,7 +758,7 @@ describe API::Projects do expect(json_response['message']).to eq('404 User Not Found') end - it 'returns projects filtered by user' do + it 'returns projects filtered by user id' do get api("/users/#{user4.id}/projects/", user) expect(response).to have_gitlab_http_status(200) @@ -733,6 +767,15 @@ describe API::Projects do expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id) end + it 'returns projects filtered by username' do + get api("/users/#{user4.username}/projects/", user) + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |project| project['id'] }).to contain_exactly(public_project.id) + end + it 'returns projects filtered by minimal access level' do private_project1 = create(:project, :private, name: 'private_project1', creator_id: user4.id, namespace: user4.namespace) private_project2 = create(:project, :private, name: 'private_project2', creator_id: user4.id, namespace: user4.namespace) @@ -746,6 +789,19 @@ describe API::Projects do expect(json_response).to be_an Array expect(json_response.map { |project| project['id'] }).to contain_exactly(private_project1.id) end + + context 'and using the programming language filter' do + include_context 'with language detection' + + it 'filters case-insensitively by programming language' do + get api('/projects', user), params: { with_programming_language: 'ruby' } + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.map { |p| p['id'] }).to contain_exactly(project.id) + end + end end describe 'POST /projects/user/:id' do |