Commit 7589af48 authored by Peter Leitzen's avatar Peter Leitzen

Add http status cop to all remaining specs

6651 files inspected, 362 offenses detected, 362 offenses corrected
parent 53ff399b
...@@ -331,26 +331,13 @@ RSpec/MissingExampleGroupArgument: ...@@ -331,26 +331,13 @@ RSpec/MissingExampleGroupArgument:
RSpec/UnspecifiedException: RSpec/UnspecifiedException:
Enabled: false Enabled: false
# Work in progress. See https://gitlab.com/gitlab-org/gitlab/issues/196163
RSpec/HaveGitlabHttpStatus: RSpec/HaveGitlabHttpStatus:
Enabled: true Enabled: true
Exclude: Exclude:
- 'spec/support/matchers/have_gitlab_http_status.rb' - 'spec/support/matchers/have_gitlab_http_status.rb'
Include: Include:
- 'spec/support/**/*' - 'spec/**/*'
- 'ee/spec/support/**/*' - 'ee/spec/**/*'
- 'spec/features/**/*'
- 'ee/spec/features/**/*'
- 'spec/controllers/**/*'
- 'ee/spec/controllers/**/*'
- 'spec/requests/*.rb'
- 'ee/spec/requests/*.rb'
- 'spec/requests/{groups,projects,repositories}/**/*'
- 'ee/spec/requests/{groups,projects,repositories}/**/*'
- 'spec/requests/api/*/**/*.rb'
- 'ee/spec/requests/api/*/**/*.rb'
- 'spec/requests/api/[a-s]*.rb'
- 'ee/spec/requests/api/[a-s]*.rb'
Style/MultilineWhenThen: Style/MultilineWhenThen:
Enabled: false Enabled: false
......
...@@ -27,7 +27,7 @@ describe API::Templates do ...@@ -27,7 +27,7 @@ describe API::Templates do
stub_licensed_features(custom_file_templates: true) stub_licensed_features(custom_file_templates: true)
get api("/templates/#{type}") get api("/templates/#{type}")
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to satisfy_one { |template| template['name'] == 'custom' } expect(json_response).to satisfy_one { |template| template['name'] == 'custom' }
end end
...@@ -35,7 +35,7 @@ describe API::Templates do ...@@ -35,7 +35,7 @@ describe API::Templates do
stub_licensed_features(custom_file_templates: false) stub_licensed_features(custom_file_templates: false)
get api("/templates/#{type}") get api("/templates/#{type}")
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to satisfy_none { |template| template['name'] == 'custom' } expect(json_response).to satisfy_none { |template| template['name'] == 'custom' }
end end
end end
...@@ -45,7 +45,7 @@ describe API::Templates do ...@@ -45,7 +45,7 @@ describe API::Templates do
stub_licensed_features(custom_file_templates: true) stub_licensed_features(custom_file_templates: true)
get api("/templates/#{type}/custom") get api("/templates/#{type}/custom")
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq('custom') expect(json_response['name']).to eq('custom')
expect(json_response['content']).to eq("Custom #{type}") expect(json_response['content']).to eq("Custom #{type}")
end end
...@@ -54,7 +54,7 @@ describe API::Templates do ...@@ -54,7 +54,7 @@ describe API::Templates do
stub_licensed_features(custom_file_templates: false) stub_licensed_features(custom_file_templates: false)
get api("/templates/#{type}/custom") get api("/templates/#{type}/custom")
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -119,7 +119,7 @@ describe API::Todos do ...@@ -119,7 +119,7 @@ describe API::Todos do
it 'returns 403 forbidden error' do it 'returns 403 forbidden error' do
subject subject
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -163,7 +163,7 @@ describe API::Todos do ...@@ -163,7 +163,7 @@ describe API::Todos do
subject subject
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -21,7 +21,7 @@ describe API::Triggers do ...@@ -21,7 +21,7 @@ describe API::Triggers do
it 'does not leak the presence of project when using valid token' do it 'does not leak the presence of project when using valid token' do
subject subject
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -31,7 +31,7 @@ describe API::Triggers do ...@@ -31,7 +31,7 @@ describe API::Triggers do
it 'does not leak the presence of project when using valid token' do it 'does not leak the presence of project when using valid token' do
subject subject
expect(response).to have_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -46,7 +46,7 @@ describe API::Triggers do ...@@ -46,7 +46,7 @@ describe API::Triggers do
it 'forbids to create a pipeline' do it 'forbids to create a pipeline' do
subject subject
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq("base" => ["Insufficient permissions to create a new pipeline"]) expect(json_response['message']).to eq("base" => ["Insufficient permissions to create a new pipeline"])
end end
end end
...@@ -59,7 +59,7 @@ describe API::Triggers do ...@@ -59,7 +59,7 @@ describe API::Triggers do
it 'creates a new pipeline' do it 'creates a new pipeline' do
expect { subject }.to change(Ci::Pipeline, :count) expect { subject }.to change(Ci::Pipeline, :count)
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(Ci::Pipeline.last.source).to eq('pipeline') expect(Ci::Pipeline.last.source).to eq('pipeline')
expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil
expect(Ci::Sources::Pipeline.last).to have_attributes( expect(Ci::Sources::Pipeline.last).to have_attributes(
...@@ -78,7 +78,7 @@ describe API::Triggers do ...@@ -78,7 +78,7 @@ describe API::Triggers do
it 'does not create a pipeline' do it 'does not create a pipeline' do
subject subject
expect(response).to have_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('400 Job has to be running') expect(json_response['message']).to eq('400 Job has to be running')
end end
end end
...@@ -93,7 +93,7 @@ describe API::Triggers do ...@@ -93,7 +93,7 @@ describe API::Triggers do
expect { subject }.to change(Ci::Pipeline, :count) expect { subject }.to change(Ci::Pipeline, :count)
.and change(Ci::PipelineVariable, :count) .and change(Ci::PipelineVariable, :count)
expect(response).to have_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(Ci::Pipeline.last.source).to eq('pipeline') expect(Ci::Pipeline.last.source).to eq('pipeline')
expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil expect(Ci::Pipeline.last.triggered_by_pipeline).not_to be_nil
expect(Ci::Pipeline.last.variables.map { |v| { v.key => v.value } }.last).to eq(params[:variables]) expect(Ci::Pipeline.last.variables.map { |v| { v.key => v.value } }.last).to eq(params[:variables])
......
...@@ -23,7 +23,7 @@ describe API::Unleash do ...@@ -23,7 +23,7 @@ describe API::Unleash do
it 'responds with OK' do it 'responds with OK' do
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
context 'when feature is not available' do context 'when feature is not available' do
...@@ -32,7 +32,7 @@ describe API::Unleash do ...@@ -32,7 +32,7 @@ describe API::Unleash do
it 'responds with forbidden' do it 'responds with forbidden' do
subject subject
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -44,7 +44,7 @@ describe API::Unleash do ...@@ -44,7 +44,7 @@ describe API::Unleash do
it 'responds with OK' do it 'responds with OK' do
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -54,7 +54,7 @@ describe API::Unleash do ...@@ -54,7 +54,7 @@ describe API::Unleash do
it 'responds with unauthorized' do it 'responds with unauthorized' do
subject subject
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -65,7 +65,7 @@ describe API::Unleash do ...@@ -65,7 +65,7 @@ describe API::Unleash do
it 'responds with unauthorized' do it 'responds with unauthorized' do
subject subject
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -168,7 +168,7 @@ describe API::Unleash do ...@@ -168,7 +168,7 @@ describe API::Unleash do
it 'responds with a list of features' do it 'responds with a list of features' do
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['version']).to eq(1) expect(json_response['version']).to eq(1)
expect(json_response['features']).not_to be_empty expect(json_response['features']).not_to be_empty
expect(json_response['features'].map { |f| f['name'] }.sort).to eq(%w[feature1 feature2]) expect(json_response['features'].map { |f| f['name'] }.sort).to eq(%w[feature1 feature2])
......
...@@ -11,7 +11,7 @@ describe API::Users do ...@@ -11,7 +11,7 @@ describe API::Users do
it 'updates the user with new name' do it 'updates the user with new name' do
put api("/users/#{user.id}", admin), params: { name: 'New Name' } put api("/users/#{user.id}", admin), params: { name: 'New Name' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['name']).to eq('New Name') expect(json_response['name']).to eq('New Name')
end end
end end
...@@ -68,7 +68,7 @@ describe API::Users do ...@@ -68,7 +68,7 @@ describe API::Users do
end.to change { user.reload.shared_runners_minutes_limit } end.to change { user.reload.shared_runners_minutes_limit }
.from(nil).to(133) .from(nil).to(133)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['shared_runners_minutes_limit']).to eq(133) expect(json_response['shared_runners_minutes_limit']).to eq(133)
end end
end end
...@@ -79,7 +79,7 @@ describe API::Users do ...@@ -79,7 +79,7 @@ describe API::Users do
put api("/users/#{user.id}", user), params: { shared_runners_minutes_limit: 133 } put api("/users/#{user.id}", user), params: { shared_runners_minutes_limit: 133 }
end.not_to change { user.reload.shared_runners_minutes_limit } end.not_to change { user.reload.shared_runners_minutes_limit }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -91,7 +91,7 @@ describe API::Users do ...@@ -91,7 +91,7 @@ describe API::Users do
it 'creates user with new identity' do it 'creates user with new identity' do
post api("/users", admin), params: attributes_for(:user, provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id) post api("/users", admin), params: attributes_for(:user, provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['identities'].first['extern_uid']).to eq('67890') expect(json_response['identities'].first['extern_uid']).to eq('67890')
expect(json_response['identities'].first['provider']).to eq('group_saml') expect(json_response['identities'].first['provider']).to eq('group_saml')
expect(json_response['identities'].first['saml_provider_id']).to eq(saml_provider.id) expect(json_response['identities'].first['saml_provider_id']).to eq(saml_provider.id)
...@@ -100,7 +100,7 @@ describe API::Users do ...@@ -100,7 +100,7 @@ describe API::Users do
it 'creates user with new identity without sending reset password email' do it 'creates user with new identity without sending reset password email' do
post api("/users", admin), params: attributes_for(:user, reset_password: false, provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id) post api("/users", admin), params: attributes_for(:user, reset_password: false, provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
new_user = User.find(json_response['id']) new_user = User.find(json_response['id'])
expect(new_user.recently_sent_password_reset?).to eq(false) expect(new_user.recently_sent_password_reset?).to eq(false)
...@@ -109,7 +109,7 @@ describe API::Users do ...@@ -109,7 +109,7 @@ describe API::Users do
it 'updates user with new identity' do it 'updates user with new identity' do
put api("/users/#{user.id}", admin), params: { provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id } put api("/users/#{user.id}", admin), params: { provider: 'group_saml', extern_uid: '67890', group_id_for_saml: saml_provider.group.id }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['identities'].first['extern_uid']).to eq('67890') expect(json_response['identities'].first['extern_uid']).to eq('67890')
expect(json_response['identities'].first['provider']).to eq('group_saml') expect(json_response['identities'].first['provider']).to eq('group_saml')
expect(json_response['identities'].first['saml_provider_id']).to eq(saml_provider.id) expect(json_response['identities'].first['saml_provider_id']).to eq(saml_provider.id)
...@@ -117,13 +117,13 @@ describe API::Users do ...@@ -117,13 +117,13 @@ describe API::Users do
it 'fails to update user with nonexistent identity' do it 'fails to update user with nonexistent identity' do
put api("/users/#{user.id}", admin), params: { provider: 'group_saml', extern_uid: '67890', group_id_for_saml: 15 } put api("/users/#{user.id}", admin), params: { provider: 'group_saml', extern_uid: '67890', group_id_for_saml: 15 }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq({ "identities.saml_provider_id" => ["can't be blank"] }) expect(json_response['message']).to eq({ "identities.saml_provider_id" => ["can't be blank"] })
end end
it 'fails to update user with nonexistent provider' do it 'fails to update user with nonexistent provider' do
put api("/users/#{user.id}", admin), params: { provider: nil, extern_uid: '67890', group_id_for_saml: saml_provider.group.id } put api("/users/#{user.id}", admin), params: { provider: nil, extern_uid: '67890', group_id_for_saml: saml_provider.group.id }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq({ "identities.provider" => ["can't be blank"] }) expect(json_response['message']).to eq({ "identities.provider" => ["can't be blank"] })
end end
end end
...@@ -183,7 +183,7 @@ describe API::Users do ...@@ -183,7 +183,7 @@ describe API::Users do
put api("/users/#{user.id}", user), params: { note: 'new note' } put api("/users/#{user.id}", user), params: { note: 'new note' }
end.not_to change { user.reload.note } end.not_to change { user.reload.note }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
......
...@@ -50,7 +50,7 @@ describe API::VisualReviewDiscussions do ...@@ -50,7 +50,7 @@ describe API::VisualReviewDiscussions do
end end
it 'responds with a status 201 Created' do it 'responds with a status 201 Created' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it 'returns the persisted note body' do it 'returns the persisted note body' do
...@@ -72,7 +72,7 @@ describe API::VisualReviewDiscussions do ...@@ -72,7 +72,7 @@ describe API::VisualReviewDiscussions do
it 'returns a 400 bad request error if body not given' do it 'returns a 400 bad request error if body not given' do
expect { request }.not_to change(merge_request.notes, :count) expect { request }.not_to change(merge_request.notes, :count)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -87,7 +87,7 @@ describe API::VisualReviewDiscussions do ...@@ -87,7 +87,7 @@ describe API::VisualReviewDiscussions do
it 'responds with a status 404' do it 'responds with a status 404' do
request request
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -107,7 +107,7 @@ describe API::VisualReviewDiscussions do ...@@ -107,7 +107,7 @@ describe API::VisualReviewDiscussions do
end end
it 'responds 403' do it 'responds 403' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it 'returns error messaging specifying that the feature is disabled' do it 'returns error messaging specifying that the feature is disabled' do
...@@ -133,7 +133,7 @@ describe API::VisualReviewDiscussions do ...@@ -133,7 +133,7 @@ describe API::VisualReviewDiscussions do
end end
it 'responds with a status 201 Created' do it 'responds with a status 201 Created' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it 'returns the persisted note body' do it 'returns the persisted note body' do
......
...@@ -25,7 +25,7 @@ describe API::Vulnerabilities do ...@@ -25,7 +25,7 @@ describe API::Vulnerabilities do
it 'returns all vulnerabilities of a project' do it 'returns all vulnerabilities of a project' do
get_vulnerabilities get_vulnerabilities
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(response).to match_response_schema('public_api/v4/vulnerabilities', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerabilities', dir: 'ee')
expect(response.headers['X-Total']).to eq project.vulnerabilities.count.to_s expect(response.headers['X-Total']).to eq project.vulnerabilities.count.to_s
...@@ -37,7 +37,7 @@ describe API::Vulnerabilities do ...@@ -37,7 +37,7 @@ describe API::Vulnerabilities do
it 'paginates the vulnerabilities according to the pagination params' do it 'paginates the vulnerabilities according to the pagination params' do
get_vulnerabilities get_vulnerabilities
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.map { |v| v['id'] }).to contain_exactly(project.vulnerabilities.second.id) expect(json_response.map { |v| v['id'] }).to contain_exactly(project.vulnerabilities.second.id)
end end
end end
...@@ -74,7 +74,7 @@ describe API::Vulnerabilities do ...@@ -74,7 +74,7 @@ describe API::Vulnerabilities do
it 'returns the desired vulnerability' do it 'returns the desired vulnerability' do
get_vulnerability get_vulnerability
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(json_response['id']).to eq vulnerability_id expect(json_response['id']).to eq vulnerability_id
end end
...@@ -82,7 +82,7 @@ describe API::Vulnerabilities do ...@@ -82,7 +82,7 @@ describe API::Vulnerabilities do
it 'returns the desired findings' do it 'returns the desired findings' do
get_vulnerability get_vulnerability
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(json_response['finding']['id']).to eq finding.id expect(json_response['finding']['id']).to eq finding.id
end end
...@@ -131,7 +131,7 @@ describe API::Vulnerabilities do ...@@ -131,7 +131,7 @@ describe API::Vulnerabilities do
report_type: finding.report_type report_type: finding.report_type
)) ))
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
end end
...@@ -141,7 +141,7 @@ describe API::Vulnerabilities do ...@@ -141,7 +141,7 @@ describe API::Vulnerabilities do
it 'responds with expected error' do it 'responds with expected error' do
subject subject
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq(expected_error_messages) expect(json_response['message']).to eq(expected_error_messages)
end end
end end
...@@ -154,7 +154,7 @@ describe API::Vulnerabilities do ...@@ -154,7 +154,7 @@ describe API::Vulnerabilities do
it 'rejects creation of a new vulnerability from this finding' do it 'rejects creation of a new vulnerability from this finding' do
subject subject
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq(expected_error_messages) expect(json_response['message']).to eq(expected_error_messages)
end end
end end
...@@ -195,7 +195,7 @@ describe API::Vulnerabilities do ...@@ -195,7 +195,7 @@ describe API::Vulnerabilities do
Timecop.freeze do Timecop.freeze do
dismiss_vulnerability dismiss_vulnerability
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(vulnerability.reload).to( expect(vulnerability.reload).to(
...@@ -231,7 +231,7 @@ describe API::Vulnerabilities do ...@@ -231,7 +231,7 @@ describe API::Vulnerabilities do
it 'responds with error' do it 'responds with error' do
dismiss_vulnerability dismiss_vulnerability
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('base' => ['something went wrong']) expect(json_response['message']).to eq('base' => ['something went wrong'])
end end
end end
...@@ -242,7 +242,7 @@ describe API::Vulnerabilities do ...@@ -242,7 +242,7 @@ describe API::Vulnerabilities do
it 'responds with 304 Not Modified' do it 'responds with 304 Not Modified' do
dismiss_vulnerability dismiss_vulnerability
expect(response).to have_gitlab_http_status(304) expect(response).to have_gitlab_http_status(:not_modified)
end end
end end
...@@ -282,7 +282,7 @@ describe API::Vulnerabilities do ...@@ -282,7 +282,7 @@ describe API::Vulnerabilities do
Timecop.freeze do Timecop.freeze do
resolve_vulnerability resolve_vulnerability
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(vulnerability.reload).to( expect(vulnerability.reload).to(
...@@ -299,7 +299,7 @@ describe API::Vulnerabilities do ...@@ -299,7 +299,7 @@ describe API::Vulnerabilities do
it 'responds with 304 Not Modified response' do it 'responds with 304 Not Modified response' do
resolve_vulnerability resolve_vulnerability
expect(response).to have_gitlab_http_status(304) expect(response).to have_gitlab_http_status(:not_modified)
end end
end end
...@@ -339,7 +339,7 @@ describe API::Vulnerabilities do ...@@ -339,7 +339,7 @@ describe API::Vulnerabilities do
Timecop.freeze do Timecop.freeze do
confirm_vulnerability confirm_vulnerability
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability', dir: 'ee')
expect(vulnerability.reload).to( expect(vulnerability.reload).to(
...@@ -356,7 +356,7 @@ describe API::Vulnerabilities do ...@@ -356,7 +356,7 @@ describe API::Vulnerabilities do
it 'responds with 304 Not Modified response' do it 'responds with 304 Not Modified response' do
confirm_vulnerability confirm_vulnerability
expect(response).to have_gitlab_http_status(304) expect(response).to have_gitlab_http_status(:not_modified)
end end
end end
......
...@@ -53,7 +53,7 @@ describe API::VulnerabilityFindings do ...@@ -53,7 +53,7 @@ describe API::VulnerabilityFindings do
get api(project_vulnerability_findings_path, user), params: pagination get api(project_vulnerability_findings_path, user), params: pagination
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(response).to match_response_schema('vulnerabilities/occurrence_list', dir: 'ee') expect(response).to match_response_schema('vulnerabilities/occurrence_list', dir: 'ee')
...@@ -78,7 +78,7 @@ describe API::VulnerabilityFindings do ...@@ -78,7 +78,7 @@ describe API::VulnerabilityFindings do
get api(project_vulnerability_findings_path, user), params: { report_type: 'sast' } get api(project_vulnerability_findings_path, user), params: { report_type: 'sast' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Total']).to eq occurrence_count expect(response.headers['X-Total']).to eq occurrence_count
...@@ -94,7 +94,7 @@ describe API::VulnerabilityFindings do ...@@ -94,7 +94,7 @@ describe API::VulnerabilityFindings do
get api(project_vulnerability_findings_path, user), params: { report_type: 'dependency_scanning' } get api(project_vulnerability_findings_path, user), params: { report_type: 'dependency_scanning' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Total']).to eq occurrence_count expect(response.headers['X-Total']).to eq occurrence_count
...@@ -108,7 +108,7 @@ describe API::VulnerabilityFindings do ...@@ -108,7 +108,7 @@ describe API::VulnerabilityFindings do
it 'returns a "bad request" response for an unknown report type' do it 'returns a "bad request" response for an unknown report type' do
get api(project_vulnerability_findings_path, user), params: { report_type: 'blah' } get api(project_vulnerability_findings_path, user), params: { report_type: 'blah' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns dismissed vulnerabilities with `all` scope' do it 'returns dismissed vulnerabilities with `all` scope' do
...@@ -116,7 +116,7 @@ describe API::VulnerabilityFindings do ...@@ -116,7 +116,7 @@ describe API::VulnerabilityFindings do
get api(project_vulnerability_findings_path, user), params: { scope: 'all' }.merge(pagination) get api(project_vulnerability_findings_path, user), params: { scope: 'all' }.merge(pagination)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Total']).to eq occurrence_count expect(response.headers['X-Total']).to eq occurrence_count
end end
...@@ -124,7 +124,7 @@ describe API::VulnerabilityFindings do ...@@ -124,7 +124,7 @@ describe API::VulnerabilityFindings do
it 'returns vulnerabilities with low severity' do it 'returns vulnerabilities with low severity' do
get api(project_vulnerability_findings_path, user), params: { severity: 'low' }.merge(pagination) get api(project_vulnerability_findings_path, user), params: { severity: 'low' }.merge(pagination)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.map { |v| v['severity'] }.uniq).to eq %w[low] expect(json_response.map { |v| v['severity'] }.uniq).to eq %w[low]
end end
...@@ -132,13 +132,13 @@ describe API::VulnerabilityFindings do ...@@ -132,13 +132,13 @@ describe API::VulnerabilityFindings do
it 'returns a "bad request" response for an unknown severity value' do it 'returns a "bad request" response for an unknown severity value' do
get api(project_vulnerability_findings_path, user), params: { severity: 'foo' } get api(project_vulnerability_findings_path, user), params: { severity: 'foo' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns vulnerabilities with high confidence' do it 'returns vulnerabilities with high confidence' do
get api(project_vulnerability_findings_path, user), params: { confidence: 'high' }.merge(pagination) get api(project_vulnerability_findings_path, user), params: { confidence: 'high' }.merge(pagination)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.map { |v| v['confidence'] }.uniq).to eq %w[high] expect(json_response.map { |v| v['confidence'] }.uniq).to eq %w[high]
end end
...@@ -146,7 +146,7 @@ describe API::VulnerabilityFindings do ...@@ -146,7 +146,7 @@ describe API::VulnerabilityFindings do
it 'returns a "bad request" response for an unknown confidence value' do it 'returns a "bad request" response for an unknown confidence value' do
get api(project_vulnerability_findings_path, user), params: { confidence: 'qux' } get api(project_vulnerability_findings_path, user), params: { confidence: 'qux' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
context 'when pipeline_id is supplied' do context 'when pipeline_id is supplied' do
...@@ -155,7 +155,7 @@ describe API::VulnerabilityFindings do ...@@ -155,7 +155,7 @@ describe API::VulnerabilityFindings do
get api(project_vulnerability_findings_path, user), params: { pipeline_id: pipeline.id }.merge(pagination) get api(project_vulnerability_findings_path, user), params: { pipeline_id: pipeline.id }.merge(pagination)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response.headers['X-Total']).to eq occurrence_count expect(response.headers['X-Total']).to eq occurrence_count
end end
...@@ -186,7 +186,7 @@ describe API::VulnerabilityFindings do ...@@ -186,7 +186,7 @@ describe API::VulnerabilityFindings do
it 'responds with 403 Forbidden' do it 'responds with 403 Forbidden' do
get api(project_vulnerability_findings_path, user) get api(project_vulnerability_findings_path, user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
......
...@@ -27,7 +27,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -27,7 +27,7 @@ describe API::VulnerabilityIssueLinks do
it 'gets the list of vulnerabilities' do it 'gets the list of vulnerabilities' do
get_issue_links get_issue_links
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/vulnerability_related_issues', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability_related_issues', dir: 'ee')
expect(json_response.map { |link| link['id'] }).to match_array(vulnerability.related_issues.map(&:id)) expect(json_response.map { |link| link['id'] }).to match_array(vulnerability.related_issues.map(&:id))
expect(json_response.map { |link| link['vulnerability_link_id'] }).to( expect(json_response.map { |link| link['vulnerability_link_id'] }).to(
...@@ -73,7 +73,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -73,7 +73,7 @@ describe API::VulnerabilityIssueLinks do
it 'creates a new vulnerability-issue link' do it 'creates a new vulnerability-issue link' do
create_issue_link create_issue_link
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/vulnerability_issue_link', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability_issue_link', dir: 'ee')
expect(json_response['issue']['id']).to eq issue.id expect(json_response['issue']['id']).to eq issue.id
expect(json_response['vulnerability']['id']).to eq vulnerability.id expect(json_response['vulnerability']['id']).to eq vulnerability.id
...@@ -86,7 +86,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -86,7 +86,7 @@ describe API::VulnerabilityIssueLinks do
it 'responds with "not found" and specific error message' do it 'responds with "not found" and specific error message' do
create_issue_link create_issue_link
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -98,7 +98,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -98,7 +98,7 @@ describe API::VulnerabilityIssueLinks do
it 'responds with "conflict" status code and specific error message' do it 'responds with "conflict" status code and specific error message' do
create_issue_link create_issue_link
expect(response).to have_gitlab_http_status(422) expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response['message']).to eq 'Issue has already been linked to another vulnerability' expect(json_response['message']).to eq 'Issue has already been linked to another vulnerability'
end end
end end
...@@ -113,7 +113,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -113,7 +113,7 @@ describe API::VulnerabilityIssueLinks do
it 'responds with "conflict" status code and specific error message' do it 'responds with "conflict" status code and specific error message' do
create_issue_link create_issue_link
expect(response).to have_gitlab_http_status(422) expect(response).to have_gitlab_http_status(:unprocessable_entity)
expect(json_response['message']).to eq 'Vulnerability already has a "created" issue link' expect(json_response['message']).to eq 'Vulnerability already has a "created" issue link'
end end
end end
...@@ -124,7 +124,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -124,7 +124,7 @@ describe API::VulnerabilityIssueLinks do
it 'creates a new vulnerability-issue link' do it 'creates a new vulnerability-issue link' do
create_issue_link create_issue_link
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
end end
...@@ -164,7 +164,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -164,7 +164,7 @@ describe API::VulnerabilityIssueLinks do
it 'deletes the specified vulnerability-issue link' do it 'deletes the specified vulnerability-issue link' do
delete_issue_link delete_issue_link
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/vulnerability_issue_link', dir: 'ee') expect(response).to match_response_schema('public_api/v4/vulnerability_issue_link', dir: 'ee')
expect(json_response['issue']['id']).to eq vulnerability_issue_link.issue.id expect(json_response['issue']['id']).to eq vulnerability_issue_link.issue.id
expect(json_response['vulnerability']['id']).to eq vulnerability_id expect(json_response['vulnerability']['id']).to eq vulnerability_id
...@@ -177,7 +177,7 @@ describe API::VulnerabilityIssueLinks do ...@@ -177,7 +177,7 @@ describe API::VulnerabilityIssueLinks do
it 'responds with "not found" and specific error message' do it 'responds with "not found" and specific error message' do
delete_issue_link delete_issue_link
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
......
...@@ -61,7 +61,7 @@ describe API::Tags do ...@@ -61,7 +61,7 @@ describe API::Tags do
it 'only returns searched tags' do it 'only returns searched tags' do
get api("#{route}", user), params: { search: 'v1.1.0' } get api("#{route}", user), params: { search: 'v1.1.0' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
...@@ -73,7 +73,7 @@ describe API::Tags do ...@@ -73,7 +73,7 @@ describe API::Tags do
it 'returns the repository tags' do it 'returns the repository tags' do
get api(route, current_user) get api(route, current_user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/tags') expect(response).to match_response_schema('public_api/v4/tags')
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response.map { |r| r['name'] }).to include(tag_name) expect(json_response.map { |r| r['name'] }).to include(tag_name)
...@@ -133,7 +133,7 @@ describe API::Tags do ...@@ -133,7 +133,7 @@ describe API::Tags do
it 'returns an array of project tags with release info' do it 'returns an array of project tags with release info' do
get api(route, user) get api(route, user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/tags') expect(response).to match_response_schema('public_api/v4/tags')
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
...@@ -151,7 +151,7 @@ describe API::Tags do ...@@ -151,7 +151,7 @@ describe API::Tags do
it 'returns the repository branch' do it 'returns the repository branch' do
get api(route, current_user) get api(route, current_user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/tag') expect(response).to match_response_schema('public_api/v4/tag')
expect(json_response['name']).to eq(tag_name) expect(json_response['name']).to eq(tag_name)
end end
...@@ -214,7 +214,7 @@ describe API::Tags do ...@@ -214,7 +214,7 @@ describe API::Tags do
it 'creates a new tag' do it 'creates a new tag' do
post api(route, current_user), params: { tag_name: tag_name, ref: 'master' } post api(route, current_user), params: { tag_name: tag_name, ref: 'master' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/tag') expect(response).to match_response_schema('public_api/v4/tag')
expect(json_response['name']).to eq(tag_name) expect(json_response['name']).to eq(tag_name)
end end
...@@ -269,26 +269,26 @@ describe API::Tags do ...@@ -269,26 +269,26 @@ describe API::Tags do
it 'returns 400 if tag name is invalid' do it 'returns 400 if tag name is invalid' do
post api(route, current_user), params: { tag_name: 'new design', ref: 'master' } post api(route, current_user), params: { tag_name: 'new design', ref: 'master' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Tag name invalid') expect(json_response['message']).to eq('Tag name invalid')
end end
it 'returns 400 if tag already exists' do it 'returns 400 if tag already exists' do
post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' } post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/tag') expect(response).to match_response_schema('public_api/v4/tag')
post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' } post api(route, current_user), params: { tag_name: 'new_design1', ref: 'master' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Tag new_design1 already exists') expect(json_response['message']).to eq('Tag new_design1 already exists')
end end
it 'returns 400 if ref name is invalid' do it 'returns 400 if ref name is invalid' do
post api(route, current_user), params: { tag_name: 'new_design3', ref: 'foo' } post api(route, current_user), params: { tag_name: 'new_design3', ref: 'foo' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Target foo is invalid') expect(json_response['message']).to eq('Target foo is invalid')
end end
...@@ -296,7 +296,7 @@ describe API::Tags do ...@@ -296,7 +296,7 @@ describe API::Tags do
it 'creates a new tag' do it 'creates a new tag' do
post api(route, current_user), params: { tag_name: tag_name, ref: 'master', release_description: 'Wow' } post api(route, current_user), params: { tag_name: tag_name, ref: 'master', release_description: 'Wow' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/tag') expect(response).to match_response_schema('public_api/v4/tag')
expect(json_response['name']).to eq(tag_name) expect(json_response['name']).to eq(tag_name)
expect(json_response['release']['description']).to eq('Wow') expect(json_response['release']['description']).to eq('Wow')
...@@ -315,7 +315,7 @@ describe API::Tags do ...@@ -315,7 +315,7 @@ describe API::Tags do
post api(route, current_user), params: { tag_name: 'v7.1.0', ref: 'master', message: 'Release 7.1.0' } post api(route, current_user), params: { tag_name: 'v7.1.0', ref: 'master', message: 'Release 7.1.0' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/tag') expect(response).to match_response_schema('public_api/v4/tag')
expect(json_response['name']).to eq('v7.1.0') expect(json_response['name']).to eq('v7.1.0')
expect(json_response['message']).to eq('Release 7.1.0') expect(json_response['message']).to eq('Release 7.1.0')
...@@ -337,7 +337,7 @@ describe API::Tags do ...@@ -337,7 +337,7 @@ describe API::Tags do
it 'deletes a tag' do it 'deletes a tag' do
delete api(route, current_user) delete api(route, current_user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end end
it_behaves_like '412 response' do it_behaves_like '412 response' do
...@@ -383,7 +383,7 @@ describe API::Tags do ...@@ -383,7 +383,7 @@ describe API::Tags do
it 'creates description for existing git tag' do it 'creates description for existing git tag' do
post api(route, user), params: { description: description } post api(route, user), params: { description: description }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema('public_api/v4/release/tag_release') expect(response).to match_response_schema('public_api/v4/release/tag_release')
expect(json_response['tag_name']).to eq(tag_name) expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(description) expect(json_response['description']).to eq(description)
...@@ -424,7 +424,7 @@ describe API::Tags do ...@@ -424,7 +424,7 @@ describe API::Tags do
it 'returns 409 if there is already a release' do it 'returns 409 if there is already a release' do
post api(route, user), params: { description: description } post api(route, user), params: { description: description }
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']).to eq('Release already exists') expect(json_response['message']).to eq('Release already exists')
end end
end end
...@@ -449,7 +449,7 @@ describe API::Tags do ...@@ -449,7 +449,7 @@ describe API::Tags do
it 'updates the release description' do it 'updates the release description' do
put api(route, current_user), params: { description: new_description } put api(route, current_user), params: { description: new_description }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['tag_name']).to eq(tag_name) expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(new_description) expect(json_response['description']).to eq(new_description)
end end
......
...@@ -57,7 +57,7 @@ describe 'task completion status response' do ...@@ -57,7 +57,7 @@ describe 'task completion status response' do
get api("#{path}?iids[]=#{taskable.iid}", user) get api("#{path}?iids[]=#{taskable.iid}", user)
end end
it { expect(response).to have_gitlab_http_status(200) } it { expect(response).to have_gitlab_http_status(:ok) }
it 'returns the expected results' do it 'returns the expected results' do
expect(json_response).to be_an Array expect(json_response).to be_an Array
......
...@@ -25,7 +25,7 @@ describe API::Templates do ...@@ -25,7 +25,7 @@ describe API::Templates do
it 'returns a list of available gitignore templates' do it 'returns a list of available gitignore templates' do
get api('/templates/gitignores') get api('/templates/gitignores')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to be > 15 expect(json_response.size).to be > 15
...@@ -36,7 +36,7 @@ describe API::Templates do ...@@ -36,7 +36,7 @@ describe API::Templates do
it 'returns a list of available gitlab_ci_ymls' do it 'returns a list of available gitlab_ci_ymls' do
get api('/templates/gitlab_ci_ymls') get api('/templates/gitlab_ci_ymls')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['name']).not_to be_nil expect(json_response.first['name']).not_to be_nil
...@@ -47,7 +47,7 @@ describe API::Templates do ...@@ -47,7 +47,7 @@ describe API::Templates do
it 'adds a disclaimer on the top' do it 'adds a disclaimer on the top' do
get api('/templates/gitlab_ci_ymls/Ruby') get api('/templates/gitlab_ci_ymls/Ruby')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['content']).to start_with("# This file is a template,") expect(json_response['content']).to start_with("# This file is a template,")
end end
end end
...@@ -58,7 +58,7 @@ describe API::Templates do ...@@ -58,7 +58,7 @@ describe API::Templates do
end end
it 'returns a license template' do it 'returns a license template' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['key']).to eq('mit') expect(json_response['key']).to eq('mit')
expect(json_response['name']).to eq('MIT License') expect(json_response['name']).to eq('MIT License')
...@@ -78,7 +78,7 @@ describe API::Templates do ...@@ -78,7 +78,7 @@ describe API::Templates do
it 'returns a list of available license templates' do it 'returns a list of available license templates' do
get api('/templates/licenses') get api('/templates/licenses')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(12) expect(json_response.size).to eq(12)
...@@ -90,7 +90,7 @@ describe API::Templates do ...@@ -90,7 +90,7 @@ describe API::Templates do
it 'returns a list of available popular license templates' do it 'returns a list of available popular license templates' do
get api('/templates/licenses?popular=1') get api('/templates/licenses?popular=1')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(3) expect(json_response.size).to eq(3)
...@@ -173,7 +173,7 @@ describe API::Templates do ...@@ -173,7 +173,7 @@ describe API::Templates do
let(:license_type) { 'muth-over9000' } let(:license_type) { 'muth-over9000' }
it 'returns a 404' do it 'returns a 404' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -185,7 +185,7 @@ describe API::Templates do ...@@ -185,7 +185,7 @@ describe API::Templates do
it 'replaces the copyright owner placeholder with the name of the current user' do it 'replaces the copyright owner placeholder with the name of the current user' do
get api('/templates/licenses/mit', user) get api('/templates/licenses/mit', user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['content']).to include("Copyright (c) #{Time.now.year} #{user.name}") expect(json_response['content']).to include("Copyright (c) #{Time.now.year} #{user.name}")
end end
end end
......
...@@ -166,7 +166,7 @@ describe API::Todos do ...@@ -166,7 +166,7 @@ describe API::Todos do
it 'returns authentication error' do it 'returns authentication error' do
post api("/todos/#{pending_1.id}/mark_as_done") post api("/todos/#{pending_1.id}/mark_as_done")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -174,7 +174,7 @@ describe API::Todos do ...@@ -174,7 +174,7 @@ describe API::Todos do
it 'marks a todo as done' do it 'marks a todo as done' do
post api("/todos/#{pending_1.id}/mark_as_done", john_doe) post api("/todos/#{pending_1.id}/mark_as_done", john_doe)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['id']).to eq(pending_1.id) expect(json_response['id']).to eq(pending_1.id)
expect(json_response['state']).to eq('done') expect(json_response['state']).to eq('done')
expect(pending_1.reload).to be_done expect(pending_1.reload).to be_done
...@@ -199,7 +199,7 @@ describe API::Todos do ...@@ -199,7 +199,7 @@ describe API::Todos do
it 'returns authentication error' do it 'returns authentication error' do
post api('/todos/mark_as_done') post api('/todos/mark_as_done')
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -207,7 +207,7 @@ describe API::Todos do ...@@ -207,7 +207,7 @@ describe API::Todos do
it 'marks all todos as done' do it 'marks all todos as done' do
post api('/todos/mark_as_done', john_doe) post api('/todos/mark_as_done', john_doe)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(pending_1.reload).to be_done expect(pending_1.reload).to be_done
expect(pending_2.reload).to be_done expect(pending_2.reload).to be_done
expect(pending_3.reload).to be_done expect(pending_3.reload).to be_done
...@@ -258,9 +258,9 @@ describe API::Todos do ...@@ -258,9 +258,9 @@ describe API::Todos do
post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", guest) post api("/projects/#{project_1.id}/#{issuable_type}/#{issuable.iid}/todo", guest)
if issuable_type == 'merge_requests' if issuable_type == 'merge_requests'
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
else else
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -31,13 +31,13 @@ describe API::Triggers do ...@@ -31,13 +31,13 @@ describe API::Triggers do
it 'returns bad request if token is missing' do it 'returns bad request if token is missing' do
post api("/projects/#{project.id}/trigger/pipeline"), params: { ref: 'master' } post api("/projects/#{project.id}/trigger/pipeline"), params: { ref: 'master' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns not found if project is not found' do it 'returns not found if project is not found' do
post api('/projects/0/trigger/pipeline'), params: options.merge(ref: 'master') post api('/projects/0/trigger/pipeline'), params: options.merge(ref: 'master')
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -47,7 +47,7 @@ describe API::Triggers do ...@@ -47,7 +47,7 @@ describe API::Triggers do
it 'creates pipeline' do it 'creates pipeline' do
post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'master') post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'master')
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response).to include('id' => pipeline.id) expect(json_response).to include('id' => pipeline.id)
pipeline.builds.reload pipeline.builds.reload
expect(pipeline.builds.pending.size).to eq(2) expect(pipeline.builds.pending.size).to eq(2)
...@@ -57,7 +57,7 @@ describe API::Triggers do ...@@ -57,7 +57,7 @@ describe API::Triggers do
it 'returns bad request with no pipeline created if there\'s no commit for that ref' do it 'returns bad request with no pipeline created if there\'s no commit for that ref' do
post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'other-branch') post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(ref: 'other-branch')
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('base' => ["Reference not found"]) expect(json_response['message']).to eq('base' => ["Reference not found"])
end end
...@@ -69,21 +69,21 @@ describe API::Triggers do ...@@ -69,21 +69,21 @@ describe API::Triggers do
it 'validates variables to be a hash' do it 'validates variables to be a hash' do
post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: 'value', ref: 'master') post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: 'value', ref: 'master')
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('variables is invalid') expect(json_response['error']).to eq('variables is invalid')
end end
it 'validates variables needs to be a map of key-valued strings' do it 'validates variables needs to be a map of key-valued strings' do
post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: { key: %w(1 2) }, ref: 'master') post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: { key: %w(1 2) }, ref: 'master')
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('variables needs to be a map of key-valued strings') expect(json_response['message']).to eq('variables needs to be a map of key-valued strings')
end end
it 'creates trigger request with variables' do it 'creates trigger request with variables' do
post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: variables, ref: 'master') post api("/projects/#{project.id}/trigger/pipeline"), params: options.merge(variables: variables, ref: 'master')
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(pipeline.variables.map { |v| { v.key => v.value } }.last).to eq(variables) expect(pipeline.variables.map { |v| { v.key => v.value } }.last).to eq(variables)
end end
end end
...@@ -93,7 +93,7 @@ describe API::Triggers do ...@@ -93,7 +93,7 @@ describe API::Triggers do
it 'does not leak the presence of project when token is for different project' do it 'does not leak the presence of project when token is for different project' do
post api("/projects/#{project2.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } post api("/projects/#{project2.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'creates builds from the ref given in the URL, not in the body' do it 'creates builds from the ref given in the URL, not in the body' do
...@@ -101,7 +101,7 @@ describe API::Triggers do ...@@ -101,7 +101,7 @@ describe API::Triggers do
post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' }
end.to change(project.builds, :count).by(5) end.to change(project.builds, :count).by(5)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
context 'when ref contains a dot' do context 'when ref contains a dot' do
...@@ -112,7 +112,7 @@ describe API::Triggers do ...@@ -112,7 +112,7 @@ describe API::Triggers do
post api("/projects/#{project.id}/ref/v.1-branch/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' } post api("/projects/#{project.id}/ref/v.1-branch/trigger/pipeline?token=#{trigger_token}"), params: { ref: 'refs/heads/other-branch' }
end.to change(project.builds, :count).by(4) end.to change(project.builds, :count).by(4)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
end end
end end
...@@ -123,7 +123,7 @@ describe API::Triggers do ...@@ -123,7 +123,7 @@ describe API::Triggers do
it 'returns a list of triggers with tokens exposed correctly' do it 'returns a list of triggers with tokens exposed correctly' do
get api("/projects/#{project.id}/triggers", user) get api("/projects/#{project.id}/triggers", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_a(Array) expect(json_response).to be_a(Array)
...@@ -137,7 +137,7 @@ describe API::Triggers do ...@@ -137,7 +137,7 @@ describe API::Triggers do
it 'does not return triggers list' do it 'does not return triggers list' do
get api("/projects/#{project.id}/triggers", user2) get api("/projects/#{project.id}/triggers", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -145,7 +145,7 @@ describe API::Triggers do ...@@ -145,7 +145,7 @@ describe API::Triggers do
it 'does not return triggers list' do it 'does not return triggers list' do
get api("/projects/#{project.id}/triggers") get api("/projects/#{project.id}/triggers")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -155,14 +155,14 @@ describe API::Triggers do ...@@ -155,14 +155,14 @@ describe API::Triggers do
it 'returns trigger details' do it 'returns trigger details' do
get api("/projects/#{project.id}/triggers/#{trigger.id}", user) get api("/projects/#{project.id}/triggers/#{trigger.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a(Hash) expect(json_response).to be_a(Hash)
end end
it 'responds with 404 Not Found if requesting non-existing trigger' do it 'responds with 404 Not Found if requesting non-existing trigger' do
get api("/projects/#{project.id}/triggers/-5", user) get api("/projects/#{project.id}/triggers/-5", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -170,7 +170,7 @@ describe API::Triggers do ...@@ -170,7 +170,7 @@ describe API::Triggers do
it 'does not return triggers list' do it 'does not return triggers list' do
get api("/projects/#{project.id}/triggers/#{trigger.id}", user2) get api("/projects/#{project.id}/triggers/#{trigger.id}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -178,7 +178,7 @@ describe API::Triggers do ...@@ -178,7 +178,7 @@ describe API::Triggers do
it 'does not return triggers list' do it 'does not return triggers list' do
get api("/projects/#{project.id}/triggers/#{trigger.id}") get api("/projects/#{project.id}/triggers/#{trigger.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -192,7 +192,7 @@ describe API::Triggers do ...@@ -192,7 +192,7 @@ describe API::Triggers do
params: { description: 'trigger' } params: { description: 'trigger' }
end.to change {project.triggers.count}.by(1) end.to change {project.triggers.count}.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response).to include('description' => 'trigger') expect(json_response).to include('description' => 'trigger')
end end
end end
...@@ -211,7 +211,7 @@ describe API::Triggers do ...@@ -211,7 +211,7 @@ describe API::Triggers do
post api("/projects/#{project.id}/triggers", user2), post api("/projects/#{project.id}/triggers", user2),
params: { description: 'trigger' } params: { description: 'trigger' }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -220,7 +220,7 @@ describe API::Triggers do ...@@ -220,7 +220,7 @@ describe API::Triggers do
post api("/projects/#{project.id}/triggers"), post api("/projects/#{project.id}/triggers"),
params: { description: 'trigger' } params: { description: 'trigger' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -233,7 +233,7 @@ describe API::Triggers do ...@@ -233,7 +233,7 @@ describe API::Triggers do
put api("/projects/#{project.id}/triggers/#{trigger.id}", user), put api("/projects/#{project.id}/triggers/#{trigger.id}", user),
params: { description: new_description } params: { description: new_description }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to include('description' => new_description) expect(json_response).to include('description' => new_description)
expect(trigger.reload.description).to eq(new_description) expect(trigger.reload.description).to eq(new_description)
end end
...@@ -243,7 +243,7 @@ describe API::Triggers do ...@@ -243,7 +243,7 @@ describe API::Triggers do
it 'does not update trigger' do it 'does not update trigger' do
put api("/projects/#{project.id}/triggers/#{trigger.id}", user2) put api("/projects/#{project.id}/triggers/#{trigger.id}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -251,7 +251,7 @@ describe API::Triggers do ...@@ -251,7 +251,7 @@ describe API::Triggers do
it 'does not update trigger' do it 'does not update trigger' do
put api("/projects/#{project.id}/triggers/#{trigger.id}") put api("/projects/#{project.id}/triggers/#{trigger.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -262,14 +262,14 @@ describe API::Triggers do ...@@ -262,14 +262,14 @@ describe API::Triggers do
expect do expect do
delete api("/projects/#{project.id}/triggers/#{trigger.id}", user) delete api("/projects/#{project.id}/triggers/#{trigger.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change {project.triggers.count}.by(-1) end.to change {project.triggers.count}.by(-1)
end end
it 'responds with 404 Not Found if requesting non-existing trigger' do it 'responds with 404 Not Found if requesting non-existing trigger' do
delete api("/projects/#{project.id}/triggers/-5", user) delete api("/projects/#{project.id}/triggers/-5", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it_behaves_like '412 response' do it_behaves_like '412 response' do
...@@ -281,7 +281,7 @@ describe API::Triggers do ...@@ -281,7 +281,7 @@ describe API::Triggers do
it 'does not delete trigger' do it 'does not delete trigger' do
delete api("/projects/#{project.id}/triggers/#{trigger.id}", user2) delete api("/projects/#{project.id}/triggers/#{trigger.id}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -289,7 +289,7 @@ describe API::Triggers do ...@@ -289,7 +289,7 @@ describe API::Triggers do
it 'does not delete trigger' do it 'does not delete trigger' do
delete api("/projects/#{project.id}/triggers/#{trigger.id}") delete api("/projects/#{project.id}/triggers/#{trigger.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
......
...@@ -41,7 +41,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -41,7 +41,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns authorization error when the `username` parameter is not passed" do it "returns authorization error when the `username` parameter is not passed" do
get api("/users") get api("/users")
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it "returns the user when a valid `username` parameter is passed" do it "returns the user when a valid `username` parameter is passed" do
...@@ -65,7 +65,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -65,7 +65,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns an empty response when an invalid `username` parameter is passed" do it "returns an empty response when an invalid `username` parameter is passed" do
get api("/users"), params: { username: 'invalid' } get api("/users"), params: { username: 'invalid' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(0) expect(json_response.size).to eq(0)
end end
...@@ -93,13 +93,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -93,13 +93,13 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns authorization error when the `username` parameter refers to an inaccessible user" do it "returns authorization error when the `username` parameter refers to an inaccessible user" do
get api("/users"), params: { username: user.username } get api("/users"), params: { username: user.username }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it "returns authorization error when the `username` parameter is not passed" do it "returns authorization error when the `username` parameter is not passed" do
get api("/users") get api("/users")
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -169,7 +169,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -169,7 +169,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns a 403 when non-admin user searches by external UID" do it "returns a 403 when non-admin user searches by external UID" do
get api("/users?extern_uid=#{omniauth_user.identities.first.extern_uid}&provider=#{omniauth_user.identities.first.provider}", user) get api("/users?extern_uid=#{omniauth_user.identities.first.extern_uid}&provider=#{omniauth_user.identities.first.provider}", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it 'does not reveal the `is_admin` flag of the user' do it 'does not reveal the `is_admin` flag of the user' do
...@@ -218,13 +218,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -218,13 +218,13 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 400 error if provider with no extern_uid" do it "returns 400 error if provider with no extern_uid" do
get api("/users?extern_uid=#{omniauth_user.identities.first.extern_uid}", admin) get api("/users?extern_uid=#{omniauth_user.identities.first.extern_uid}", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns 400 error if provider with no extern_uid" do it "returns 400 error if provider with no extern_uid" do
get api("/users?provider=#{omniauth_user.identities.first.provider}", admin) get api("/users?provider=#{omniauth_user.identities.first.provider}", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a user created before a specific date" do it "returns a user created before a specific date" do
...@@ -283,7 +283,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -283,7 +283,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 400 when provided incorrect sort params' do it 'returns 400 when provided incorrect sort params' do
get api('/users', admin), params: { order_by: 'magic', sort: 'asc' } get api('/users', admin), params: { order_by: 'magic', sort: 'asc' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -293,7 +293,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -293,7 +293,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users", user), params: { skip_ldap: "true" } get api("/users", user), params: { skip_ldap: "true" }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["username"]).to eq user.username expect(json_response.first["username"]).to eq user.username
end end
...@@ -388,7 +388,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -388,7 +388,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user.id}") get api("/users/#{user.id}")
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it "returns the `created_at` field for public users" do it "returns the `created_at` field for public users" do
...@@ -409,14 +409,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -409,14 +409,14 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns a 404 error if user id not found" do it "returns a 404 error if user id not found" do
get api("/users/0", user) get api("/users/0", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
get api("/users/1ASDF", user) get api("/users/1ASDF", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -453,7 +453,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -453,7 +453,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "creates user with correct attributes" do it "creates user with correct attributes" do
post api('/users', admin), params: attributes_for(:user, admin: true, can_create_group: true) post api('/users', admin), params: attributes_for(:user, admin: true, can_create_group: true)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user.admin).to eq(true) expect(new_user.admin).to eq(true)
...@@ -466,12 +466,12 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -466,12 +466,12 @@ describe API::Users, :do_not_mock_admin_mode do
post api('/users', admin), params: attributes post api('/users', admin), params: attributes
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it "creates non-admin user" do it "creates non-admin user" do
post api('/users', admin), params: attributes_for(:user, admin: false, can_create_group: false) post api('/users', admin), params: attributes_for(:user, admin: false, can_create_group: false)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user.admin).to eq(false) expect(new_user.admin).to eq(false)
...@@ -480,7 +480,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -480,7 +480,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "creates non-admin users by default" do it "creates non-admin users by default" do
post api('/users', admin), params: attributes_for(:user) post api('/users', admin), params: attributes_for(:user)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
expect(new_user.admin).to eq(false) expect(new_user.admin).to eq(false)
...@@ -489,12 +489,12 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -489,12 +489,12 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 201 Created on success" do it "returns 201 Created on success" do
post api("/users", admin), params: attributes_for(:user, projects_limit: 3) post api("/users", admin), params: attributes_for(:user, projects_limit: 3)
expect(response).to match_response_schema('public_api/v4/user/admin') expect(response).to match_response_schema('public_api/v4/user/admin')
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it 'creates non-external users by default' do it 'creates non-external users by default' do
post api("/users", admin), params: attributes_for(:user) post api("/users", admin), params: attributes_for(:user)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -503,7 +503,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -503,7 +503,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'allows an external user to be created' do it 'allows an external user to be created' do
post api("/users", admin), params: attributes_for(:user, external: true) post api("/users", admin), params: attributes_for(:user, external: true)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -513,7 +513,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -513,7 +513,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "creates user with reset password" do it "creates user with reset password" do
post api('/users', admin), params: attributes_for(:user, reset_password: true).except(:password) post api('/users', admin), params: attributes_for(:user, reset_password: true).except(:password)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -525,7 +525,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -525,7 +525,7 @@ describe API::Users, :do_not_mock_admin_mode do
params = attributes_for(:user, force_random_password: true, reset_password: true) params = attributes_for(:user, force_random_password: true, reset_password: true)
post api('/users', admin), params: params post api('/users', admin), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -537,7 +537,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -537,7 +537,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "creates user with private profile" do it "creates user with private profile" do
post api('/users', admin), params: attributes_for(:user, private_profile: true) post api('/users', admin), params: attributes_for(:user, private_profile: true)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
user_id = json_response['id'] user_id = json_response['id']
new_user = User.find(user_id) new_user = User.find(user_id)
...@@ -553,27 +553,27 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -553,27 +553,27 @@ describe API::Users, :do_not_mock_admin_mode do
password: 'password', password: 'password',
name: 'test' name: 'test'
} }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 error if name not given' do it 'returns 400 error if name not given' do
post api('/users', admin), params: attributes_for(:user).except(:name) post api('/users', admin), params: attributes_for(:user).except(:name)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 error if password not given' do it 'returns 400 error if password not given' do
post api('/users', admin), params: attributes_for(:user).except(:password) post api('/users', admin), params: attributes_for(:user).except(:password)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 error if email not given' do it 'returns 400 error if email not given' do
post api('/users', admin), params: attributes_for(:user).except(:email) post api('/users', admin), params: attributes_for(:user).except(:email)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 error if username not given' do it 'returns 400 error if username not given' do
post api('/users', admin), params: attributes_for(:user).except(:username) post api('/users', admin), params: attributes_for(:user).except(:username)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "doesn't create user with invalid optional attributes" do it "doesn't create user with invalid optional attributes" do
...@@ -582,7 +582,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -582,7 +582,7 @@ describe API::Users, :do_not_mock_admin_mode do
post api('/users', admin), params: attributes post api('/users', admin), params: attributes
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 error if user does not validate' do it 'returns 400 error if user does not validate' do
...@@ -595,7 +595,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -595,7 +595,7 @@ describe API::Users, :do_not_mock_admin_mode do
bio: 'g' * 256, bio: 'g' * 256,
projects_limit: -1 projects_limit: -1
} }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['password']) expect(json_response['message']['password'])
.to eq(['is too short (minimum is 8 characters)']) .to eq(['is too short (minimum is 8 characters)'])
expect(json_response['message']['bio']) expect(json_response['message']['bio'])
...@@ -608,7 +608,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -608,7 +608,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "is not available for non admin users" do it "is not available for non admin users" do
post api("/users", user), params: attributes_for(:user) post api("/users", user), params: attributes_for(:user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
context 'with existing user' do context 'with existing user' do
...@@ -632,7 +632,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -632,7 +632,7 @@ describe API::Users, :do_not_mock_admin_mode do
username: 'foo' username: 'foo'
} }
end.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']).to eq('Email has already been taken') expect(json_response['message']).to eq('Email has already been taken')
end end
...@@ -646,7 +646,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -646,7 +646,7 @@ describe API::Users, :do_not_mock_admin_mode do
username: 'test' username: 'test'
} }
end.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']).to eq('Username has already been taken') expect(json_response['message']).to eq('Username has already been taken')
end end
...@@ -660,14 +660,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -660,14 +660,14 @@ describe API::Users, :do_not_mock_admin_mode do
username: 'TEST' username: 'TEST'
} }
end.to change { User.count }.by(0) end.to change { User.count }.by(0)
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(json_response['message']).to eq('Username has already been taken') expect(json_response['message']).to eq('Username has already been taken')
end end
it 'creates user with new identity' do it 'creates user with new identity' do
post api("/users", admin), params: attributes_for(:user, provider: 'github', extern_uid: '67890') post api("/users", admin), params: attributes_for(:user, provider: 'github', extern_uid: '67890')
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['identities'].first['extern_uid']).to eq('67890') expect(json_response['identities'].first['extern_uid']).to eq('67890')
expect(json_response['identities'].first['provider']).to eq('github') expect(json_response['identities'].first['provider']).to eq('github')
end end
...@@ -689,13 +689,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -689,13 +689,13 @@ describe API::Users, :do_not_mock_admin_mode do
put api("/users/#{user.id}", admin), params: { bio: 'new test bio' } put api("/users/#{user.id}", admin), params: { bio: 'new test bio' }
expect(response).to match_response_schema('public_api/v4/user/admin') expect(response).to match_response_schema('public_api/v4/user/admin')
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it "updates user with new bio" do it "updates user with new bio" do
put api("/users/#{user.id}", admin), params: { bio: 'new test bio' } put api("/users/#{user.id}", admin), params: { bio: 'new test bio' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['bio']).to eq('new test bio') expect(json_response['bio']).to eq('new test bio')
expect(user.reload.bio).to eq('new test bio') expect(user.reload.bio).to eq('new test bio')
end end
...@@ -703,14 +703,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -703,14 +703,14 @@ describe API::Users, :do_not_mock_admin_mode do
it "updates user with new password and forces reset on next login" do it "updates user with new password and forces reset on next login" do
put api("/users/#{user.id}", admin), params: { password: '12345678' } put api("/users/#{user.id}", admin), params: { password: '12345678' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.password_expires_at).to be <= Time.now expect(user.reload.password_expires_at).to be <= Time.now
end end
it "updates user with organization" do it "updates user with organization" do
put api("/users/#{user.id}", admin), params: { organization: 'GitLab' } put api("/users/#{user.id}", admin), params: { organization: 'GitLab' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['organization']).to eq('GitLab') expect(json_response['organization']).to eq('GitLab')
expect(user.reload.organization).to eq('GitLab') expect(user.reload.organization).to eq('GitLab')
end end
...@@ -721,7 +721,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -721,7 +721,7 @@ describe API::Users, :do_not_mock_admin_mode do
user.reload user.reload
expect(user.avatar).to be_present expect(user.avatar).to be_present
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['avatar_url']).to include(user.avatar_path) expect(json_response['avatar_url']).to include(user.avatar_path)
end end
...@@ -732,7 +732,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -732,7 +732,7 @@ describe API::Users, :do_not_mock_admin_mode do
user.reload user.reload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user).to be_confirmed expect(user).to be_confirmed
expect(user.email).to eq(old_email) expect(user.email).to eq(old_email)
expect(user.notification_email).to eq(old_notification_email) expect(user.notification_email).to eq(old_notification_email)
...@@ -744,7 +744,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -744,7 +744,7 @@ describe API::Users, :do_not_mock_admin_mode do
user.reload user.reload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user).to be_confirmed expect(user).to be_confirmed
expect(user.email).to eq('new@email.com') expect(user.email).to eq('new@email.com')
end end
...@@ -752,7 +752,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -752,7 +752,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'updates user with their own username' do it 'updates user with their own username' do
put api("/users/#{user.id}", admin), params: { username: user.username } put api("/users/#{user.id}", admin), params: { username: user.username }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['username']).to eq(user.username) expect(json_response['username']).to eq(user.username)
expect(user.reload.username).to eq(user.username) expect(user.reload.username).to eq(user.username)
end end
...@@ -760,14 +760,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -760,14 +760,14 @@ describe API::Users, :do_not_mock_admin_mode do
it "updates user's existing identity" do it "updates user's existing identity" do
put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldapmain', extern_uid: '654321' } put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldapmain', extern_uid: '654321' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321') expect(omniauth_user.reload.identities.first.extern_uid).to eq('654321')
end end
it 'updates user with new identity' do it 'updates user with new identity' do
put api("/users/#{user.id}", admin), params: { provider: 'github', extern_uid: 'john' } put api("/users/#{user.id}", admin), params: { provider: 'github', extern_uid: 'john' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.identities.first.extern_uid).to eq('john') expect(user.reload.identities.first.extern_uid).to eq('john')
expect(user.reload.identities.first.provider).to eq('github') expect(user.reload.identities.first.provider).to eq('github')
end end
...@@ -775,7 +775,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -775,7 +775,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "updates admin status" do it "updates admin status" do
put api("/users/#{user.id}", admin), params: { admin: true } put api("/users/#{user.id}", admin), params: { admin: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.admin).to eq(true) expect(user.reload.admin).to eq(true)
end end
...@@ -796,7 +796,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -796,7 +796,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "updates private profile" do it "updates private profile" do
put api("/users/#{user.id}", admin), params: { private_profile: true } put api("/users/#{user.id}", admin), params: { private_profile: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.private_profile).to eq(true) expect(user.reload.private_profile).to eq(true)
end end
...@@ -805,7 +805,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -805,7 +805,7 @@ describe API::Users, :do_not_mock_admin_mode do
put api("/users/#{user.id}", admin), params: { private_profile: nil } put api("/users/#{user.id}", admin), params: { private_profile: nil }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.private_profile).to eq(false) expect(user.reload.private_profile).to eq(false)
end end
...@@ -814,14 +814,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -814,14 +814,14 @@ describe API::Users, :do_not_mock_admin_mode do
put api("/users/#{user.id}", admin), params: {} put api("/users/#{user.id}", admin), params: {}
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.private_profile).to eq(true) expect(user.reload.private_profile).to eq(true)
end end
it "does not update admin status" do it "does not update admin status" do
put api("/users/#{admin_user.id}", admin), params: { can_create_group: false } put api("/users/#{admin_user.id}", admin), params: { can_create_group: false }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(admin_user.reload.admin).to eq(true) expect(admin_user.reload.admin).to eq(true)
expect(admin_user.can_create_group).to eq(false) expect(admin_user.can_create_group).to eq(false)
end end
...@@ -829,35 +829,35 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -829,35 +829,35 @@ describe API::Users, :do_not_mock_admin_mode do
it "does not allow invalid update" do it "does not allow invalid update" do
put api("/users/#{user.id}", admin), params: { email: 'invalid email' } put api("/users/#{user.id}", admin), params: { email: 'invalid email' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(user.reload.email).not_to eq('invalid email') expect(user.reload.email).not_to eq('invalid email')
end end
it "updates theme id" do it "updates theme id" do
put api("/users/#{user.id}", admin), params: { theme_id: 5 } put api("/users/#{user.id}", admin), params: { theme_id: 5 }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.theme_id).to eq(5) expect(user.reload.theme_id).to eq(5)
end end
it "does not update invalid theme id" do it "does not update invalid theme id" do
put api("/users/#{user.id}", admin), params: { theme_id: 50 } put api("/users/#{user.id}", admin), params: { theme_id: 50 }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(user.reload.theme_id).not_to eq(50) expect(user.reload.theme_id).not_to eq(50)
end end
it "updates color scheme id" do it "updates color scheme id" do
put api("/users/#{user.id}", admin), params: { color_scheme_id: 5 } put api("/users/#{user.id}", admin), params: { color_scheme_id: 5 }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(user.reload.color_scheme_id).to eq(5) expect(user.reload.color_scheme_id).to eq(5)
end end
it "does not update invalid color scheme id" do it "does not update invalid color scheme id" do
put api("/users/#{user.id}", admin), params: { color_scheme_id: 50 } put api("/users/#{user.id}", admin), params: { color_scheme_id: 50 }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(user.reload.color_scheme_id).not_to eq(50) expect(user.reload.color_scheme_id).not_to eq(50)
end end
...@@ -867,21 +867,21 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -867,21 +867,21 @@ describe API::Users, :do_not_mock_admin_mode do
put api("/users/#{user.id}", user), params: attributes_for(:user) put api("/users/#{user.id}", user), params: attributes_for(:user)
end.not_to change { user.reload.attributes } end.not_to change { user.reload.attributes }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
it "returns 404 for non-existing user" do it "returns 404 for non-existing user" do
put api("/users/0", admin), params: { bio: 'update should fail' } put api("/users/0", admin), params: { bio: 'update should fail' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it "returns a 404 if invalid ID" do it "returns a 404 if invalid ID" do
put api("/users/ASDF", admin) put api("/users/ASDF", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns 400 error if user does not validate' do it 'returns 400 error if user does not validate' do
...@@ -894,7 +894,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -894,7 +894,7 @@ describe API::Users, :do_not_mock_admin_mode do
bio: 'g' * 256, bio: 'g' * 256,
projects_limit: -1 projects_limit: -1
} }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['password']) expect(json_response['message']['password'])
.to eq(['is too short (minimum is 8 characters)']) .to eq(['is too short (minimum is 8 characters)'])
expect(json_response['message']['bio']) expect(json_response['message']['bio'])
...@@ -908,13 +908,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -908,13 +908,13 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 400 if provider is missing for identity update' do it 'returns 400 if provider is missing for identity update' do
put api("/users/#{omniauth_user.id}", admin), params: { extern_uid: '654321' } put api("/users/#{omniauth_user.id}", admin), params: { extern_uid: '654321' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'returns 400 if external UID is missing for identity update' do it 'returns 400 if external UID is missing for identity update' do
put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldap' } put api("/users/#{omniauth_user.id}", admin), params: { provider: 'ldap' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
context "with existing user" do context "with existing user" do
...@@ -927,7 +927,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -927,7 +927,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 409 conflict error if email address exists' do it 'returns 409 conflict error if email address exists' do
put api("/users/#{@user.id}", admin), params: { email: 'test@example.com' } put api("/users/#{@user.id}", admin), params: { email: 'test@example.com' }
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(@user.reload.email).to eq(@user.email) expect(@user.reload.email).to eq(@user.email)
end end
...@@ -935,7 +935,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -935,7 +935,7 @@ describe API::Users, :do_not_mock_admin_mode do
@user_id = User.all.last.id @user_id = User.all.last.id
put api("/users/#{@user.id}", admin), params: { username: 'test' } put api("/users/#{@user.id}", admin), params: { username: 'test' }
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(@user.reload.username).to eq(@user.username) expect(@user.reload.username).to eq(@user.username)
end end
...@@ -943,7 +943,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -943,7 +943,7 @@ describe API::Users, :do_not_mock_admin_mode do
@user_id = User.all.last.id @user_id = User.all.last.id
put api("/users/#{@user.id}", admin), params: { username: 'TEST' } put api("/users/#{@user.id}", admin), params: { username: 'TEST' }
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
expect(@user.reload.username).to eq(@user.username) expect(@user.reload.username).to eq(@user.username)
end end
end end
...@@ -996,14 +996,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -996,14 +996,14 @@ describe API::Users, :do_not_mock_admin_mode do
it "does not create invalid ssh key" do it "does not create invalid ssh key" do
post api("/users/#{user.id}/keys", admin), params: { title: "invalid key" } post api("/users/#{user.id}/keys", admin), params: { title: "invalid key" }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('key is missing') expect(json_response['error']).to eq('key is missing')
end end
it 'does not create key without title' do it 'does not create key without title' do
post api("/users/#{user.id}/keys", admin), params: { key: 'some key' } post api("/users/#{user.id}/keys", admin), params: { key: 'some key' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('title is missing') expect(json_response['error']).to eq('title is missing')
end end
...@@ -1016,7 +1016,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1016,7 +1016,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 400 for invalid ID" do it "returns 400 for invalid ID" do
post api("/users/0/keys", admin) post api("/users/0/keys", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -1026,7 +1026,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1026,7 +1026,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user_id}/keys") get api("/users/#{user_id}/keys")
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -1036,7 +1036,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1036,7 +1036,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user.id}/keys") get api("/users/#{user.id}/keys")
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(key.title) expect(json_response.first['title']).to eq(key.title)
...@@ -1047,7 +1047,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1047,7 +1047,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 404 for non-existing user' do it 'returns 404 for non-existing user' do
get api("/users/#{not_existing_user_id}/keys") get api("/users/#{not_existing_user_id}/keys")
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -1057,7 +1057,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1057,7 +1057,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user.username}/keys") get api("/users/#{user.username}/keys")
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(key.title) expect(json_response.first['title']).to eq(key.title)
...@@ -1072,7 +1072,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1072,7 +1072,7 @@ describe API::Users, :do_not_mock_admin_mode do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
delete api("/users/#{user.id}/keys/42") delete api("/users/#{user.id}/keys/42")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1084,7 +1084,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1084,7 +1084,7 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/users/#{user.id}/keys/#{key.id}", admin) delete api("/users/#{user.id}/keys/#{key.id}", admin)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.keys.count }.by(-1) end.to change { user.keys.count }.by(-1)
end end
...@@ -1096,13 +1096,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1096,13 +1096,13 @@ describe API::Users, :do_not_mock_admin_mode do
user.keys << key user.keys << key
user.save user.save
delete api("/users/0/keys/#{key.id}", admin) delete api("/users/0/keys/#{key.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns 404 error if key not foud' do it 'returns 404 error if key not foud' do
delete api("/users/#{user.id}/keys/42", admin) delete api("/users/#{user.id}/keys/42", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Key Not Found') expect(json_response['message']).to eq('404 Key Not Found')
end end
end end
...@@ -1116,7 +1116,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1116,7 +1116,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'does not create invalid GPG key' do it 'does not create invalid GPG key' do
post api("/users/#{user.id}/gpg_keys", admin) post api("/users/#{user.id}/gpg_keys", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('key is missing') expect(json_response['error']).to eq('key is missing')
end end
...@@ -1125,14 +1125,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1125,14 +1125,14 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
post api("/users/#{user.id}/gpg_keys", admin), params: key_attrs post api("/users/#{user.id}/gpg_keys", admin), params: key_attrs
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end.to change { user.gpg_keys.count }.by(1) end.to change { user.gpg_keys.count }.by(1)
end end
it 'returns 400 for invalid ID' do it 'returns 400 for invalid ID' do
post api('/users/0/gpg_keys', admin) post api('/users/0/gpg_keys', admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -1145,7 +1145,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1145,7 +1145,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns authentication error' do it 'returns authentication error' do
get api("/users/#{user.id}/gpg_keys") get api("/users/#{user.id}/gpg_keys")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1153,14 +1153,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1153,14 +1153,14 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 404 for non-existing user' do it 'returns 404 for non-existing user' do
get api('/users/0/gpg_keys', admin) get api('/users/0/gpg_keys', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns 404 error if key not foud' do it 'returns 404 error if key not foud' do
delete api("/users/#{user.id}/gpg_keys/42", admin) delete api("/users/#{user.id}/gpg_keys/42", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
...@@ -1170,7 +1170,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1170,7 +1170,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user.id}/gpg_keys", admin) get api("/users/#{user.id}/gpg_keys", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['key']).to eq(gpg_key.key) expect(json_response.first['key']).to eq(gpg_key.key)
...@@ -1187,7 +1187,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1187,7 +1187,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns authentication error' do it 'returns authentication error' do
delete api("/users/#{user.id}/keys/42") delete api("/users/#{user.id}/keys/42")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1199,7 +1199,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1199,7 +1199,7 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/users/#{user.id}/gpg_keys/#{gpg_key.id}", admin) delete api("/users/#{user.id}/gpg_keys/#{gpg_key.id}", admin)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.gpg_keys.count }.by(-1) end.to change { user.gpg_keys.count }.by(-1)
end end
...@@ -1209,14 +1209,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1209,14 +1209,14 @@ describe API::Users, :do_not_mock_admin_mode do
delete api("/users/0/gpg_keys/#{gpg_key.id}", admin) delete api("/users/0/gpg_keys/#{gpg_key.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns 404 error if key not foud' do it 'returns 404 error if key not foud' do
delete api("/users/#{user.id}/gpg_keys/42", admin) delete api("/users/#{user.id}/gpg_keys/42", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
end end
...@@ -1231,7 +1231,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1231,7 +1231,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns authentication error' do it 'returns authentication error' do
post api("/users/#{user.id}/gpg_keys/42/revoke") post api("/users/#{user.id}/gpg_keys/42/revoke")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1253,14 +1253,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1253,14 +1253,14 @@ describe API::Users, :do_not_mock_admin_mode do
post api("/users/0/gpg_keys/#{gpg_key.id}/revoke", admin) post api("/users/0/gpg_keys/#{gpg_key.id}/revoke", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns 404 error if key not foud' do it 'returns 404 error if key not foud' do
post api("/users/#{user.id}/gpg_keys/42/revoke", admin) post api("/users/#{user.id}/gpg_keys/42/revoke", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
end end
...@@ -1274,7 +1274,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1274,7 +1274,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "does not create invalid email" do it "does not create invalid email" do
post api("/users/#{user.id}/emails", admin), params: {} post api("/users/#{user.id}/emails", admin), params: {}
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('email is missing') expect(json_response['error']).to eq('email is missing')
end end
...@@ -1291,7 +1291,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1291,7 +1291,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns a 400 for invalid ID" do it "returns a 400 for invalid ID" do
post api("/users/0/emails", admin) post api("/users/0/emails", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "creates verified email" do it "creates verified email" do
...@@ -1300,7 +1300,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1300,7 +1300,7 @@ describe API::Users, :do_not_mock_admin_mode do
post api("/users/#{user.id}/emails", admin), params: email_attrs post api("/users/#{user.id}/emails", admin), params: email_attrs
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
email = Email.find_by(user_id: user.id, email: email_attrs[:email]) email = Email.find_by(user_id: user.id, email: email_attrs[:email])
expect(email).to be_confirmed expect(email).to be_confirmed
...@@ -1315,14 +1315,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1315,14 +1315,14 @@ describe API::Users, :do_not_mock_admin_mode do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
get api("/users/#{user.id}/emails") get api("/users/#{user.id}/emails")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
context 'when authenticated' do context 'when authenticated' do
it 'returns 404 for non-existing user' do it 'returns 404 for non-existing user' do
get api('/users/0/emails', admin) get api('/users/0/emails', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -1332,7 +1332,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1332,7 +1332,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/users/#{user.id}/emails", admin) get api("/users/#{user.id}/emails", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['email']).to eq(email.email) expect(json_response.first['email']).to eq(email.email)
...@@ -1341,7 +1341,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1341,7 +1341,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
get api("/users/ASDF/emails", admin) get api("/users/ASDF/emails", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -1354,7 +1354,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1354,7 +1354,7 @@ describe API::Users, :do_not_mock_admin_mode do
context 'when unauthenticated' do context 'when unauthenticated' do
it 'returns authentication error' do it 'returns authentication error' do
delete api("/users/#{user.id}/emails/42") delete api("/users/#{user.id}/emails/42")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1366,7 +1366,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1366,7 +1366,7 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/users/#{user.id}/emails/#{email.id}", admin) delete api("/users/#{user.id}/emails/#{email.id}", admin)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.emails.count }.by(-1) end.to change { user.emails.count }.by(-1)
end end
...@@ -1378,20 +1378,20 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1378,20 +1378,20 @@ describe API::Users, :do_not_mock_admin_mode do
user.emails << email user.emails << email
user.save user.save
delete api("/users/0/emails/#{email.id}", admin) delete api("/users/0/emails/#{email.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns 404 error if email not foud' do it 'returns 404 error if email not foud' do
delete api("/users/#{user.id}/emails/42", admin) delete api("/users/#{user.id}/emails/42", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Email Not Found') expect(json_response['message']).to eq('404 Email Not Found')
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
delete api("/users/ASDF/emails/bar", admin) delete api("/users/ASDF/emails/bar", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -1407,7 +1407,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1407,7 +1407,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "deletes user", :sidekiq_might_not_need_inline do it "deletes user", :sidekiq_might_not_need_inline do
perform_enqueued_jobs { delete api("/users/#{user.id}", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
expect { Namespace.find(namespace.id) }.to raise_error ActiveRecord::RecordNotFound expect { Namespace.find(namespace.id) }.to raise_error ActiveRecord::RecordNotFound
end end
...@@ -1418,14 +1418,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1418,14 +1418,14 @@ describe API::Users, :do_not_mock_admin_mode do
context "hard delete disabled" do context "hard delete disabled" do
it "does not delete user" do it "does not delete user" do
perform_enqueued_jobs { delete api("/users/#{user.id}", admin)} perform_enqueued_jobs { delete api("/users/#{user.id}", admin)}
expect(response).to have_gitlab_http_status(409) expect(response).to have_gitlab_http_status(:conflict)
end end
end end
context "hard delete enabled" do context "hard delete enabled" do
it "delete user and group", :sidekiq_might_not_need_inline do it "delete user and group", :sidekiq_might_not_need_inline do
perform_enqueued_jobs { delete api("/users/#{user.id}?hard_delete=true", admin)} perform_enqueued_jobs { delete api("/users/#{user.id}?hard_delete=true", admin)}
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(Group.exists?(group.id)).to be_falsy expect(Group.exists?(group.id)).to be_falsy
end end
end end
...@@ -1437,31 +1437,31 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1437,31 +1437,31 @@ describe API::Users, :do_not_mock_admin_mode do
it "does not delete for unauthenticated user" do it "does not delete for unauthenticated user" do
perform_enqueued_jobs { delete api("/users/#{user.id}") } perform_enqueued_jobs { delete api("/users/#{user.id}") }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "is not available for non admin users" do it "is not available for non admin users" do
perform_enqueued_jobs { delete api("/users/#{user.id}", user) } perform_enqueued_jobs { delete api("/users/#{user.id}", user) }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it "returns 404 for non-existing user" do it "returns 404 for non-existing user" do
perform_enqueued_jobs { delete api("/users/0", admin) } perform_enqueued_jobs { delete api("/users/0", admin) }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
perform_enqueued_jobs { delete api("/users/ASDF", admin) } perform_enqueued_jobs { delete api("/users/ASDF", admin) }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
context "hard delete disabled" do context "hard delete disabled" do
it "moves contributions to the ghost user", :sidekiq_might_not_need_inline do it "moves contributions to the ghost user", :sidekiq_might_not_need_inline do
perform_enqueued_jobs { delete api("/users/#{user.id}", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(issue.reload).to be_persisted expect(issue.reload).to be_persisted
expect(issue.author.ghost?).to be_truthy expect(issue.author.ghost?).to be_truthy
end end
...@@ -1471,7 +1471,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1471,7 +1471,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "removes contributions", :sidekiq_might_not_need_inline do it "removes contributions", :sidekiq_might_not_need_inline do
perform_enqueued_jobs { delete api("/users/#{user.id}?hard_delete=true", admin) } perform_enqueued_jobs { delete api("/users/#{user.id}?hard_delete=true", admin) }
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(Issue.exists?(issue.id)).to be_falsy expect(Issue.exists?(issue.id)).to be_falsy
end end
end end
...@@ -1486,14 +1486,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1486,14 +1486,14 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 403 without private token when sudo is defined' do it 'returns 403 without private token when sudo is defined' do
get api("/user?private_token=#{personal_access_token}&sudo=123", version: version) get api("/user?private_token=#{personal_access_token}&sudo=123", version: version)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
it 'returns current user without private token when sudo not defined' do it 'returns current user without private token when sudo not defined' do
get api("/user", user, version: version) get api("/user", user, version: version)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/user/public') expect(response).to match_response_schema('public_api/v4/user/public')
expect(json_response['id']).to eq(user.id) expect(json_response['id']).to eq(user.id)
end end
...@@ -1513,13 +1513,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1513,13 +1513,13 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 403 without private token when sudo defined' do it 'returns 403 without private token when sudo defined' do
get api("/user?private_token=#{admin_personal_access_token}&sudo=#{user.id}", version: version) get api("/user?private_token=#{admin_personal_access_token}&sudo=#{user.id}", version: version)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
it 'returns initial current user without private token but with is_admin when sudo not defined' do it 'returns initial current user without private token but with is_admin when sudo not defined' do
get api("/user?private_token=#{admin_personal_access_token}", version: version) get api("/user?private_token=#{admin_personal_access_token}", version: version)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('public_api/v4/user/admin') expect(response).to match_response_schema('public_api/v4/user/admin')
expect(json_response['id']).to eq(admin.id) expect(json_response['id']).to eq(admin.id)
end end
...@@ -1530,7 +1530,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1530,7 +1530,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 401 error if user is unauthenticated" do it "returns 401 error if user is unauthenticated" do
get api("/user", version: version) get api("/user", version: version)
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -1543,7 +1543,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1543,7 +1543,7 @@ describe API::Users, :do_not_mock_admin_mode do
context "when unauthenticated" do context "when unauthenticated" do
it "returns authentication error" do it "returns authentication error" do
get api("/user/keys") get api("/user/keys")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1554,7 +1554,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1554,7 +1554,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/user/keys", user) get api("/user/keys", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["title"]).to eq(key.title) expect(json_response.first["title"]).to eq(key.title)
...@@ -1574,14 +1574,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1574,14 +1574,14 @@ describe API::Users, :do_not_mock_admin_mode do
user.keys << key user.keys << key
user.save user.save
get api("/user/keys/#{key.id}", user) get api("/user/keys/#{key.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response["title"]).to eq(key.title) expect(json_response["title"]).to eq(key.title)
end end
it "returns 404 Not Found within invalid ID" do it "returns 404 Not Found within invalid ID" do
get api("/user/keys/42", user) get api("/user/keys/42", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Key Not Found') expect(json_response['message']).to eq('404 Key Not Found')
end end
...@@ -1590,14 +1590,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1590,14 +1590,14 @@ describe API::Users, :do_not_mock_admin_mode do
user.save user.save
admin admin
get api("/user/keys/#{key.id}", admin) get api("/user/keys/#{key.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Key Not Found') expect(json_response['message']).to eq('404 Key Not Found')
end end
it "returns 404 for invalid ID" do it "returns 404 for invalid ID" do
get api("/users/keys/ASDF", admin) get api("/users/keys/ASDF", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
context "scopes" do context "scopes" do
...@@ -1614,31 +1614,31 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1614,31 +1614,31 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
post api("/user/keys", user), params: key_attrs post api("/user/keys", user), params: key_attrs
end.to change { user.keys.count }.by(1) end.to change { user.keys.count }.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it "returns a 401 error if unauthorized" do it "returns a 401 error if unauthorized" do
post api("/user/keys"), params: { title: 'some title', key: 'some key' } post api("/user/keys"), params: { title: 'some title', key: 'some key' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "does not create ssh key without key" do it "does not create ssh key without key" do
post api("/user/keys", user), params: { title: 'title' } post api("/user/keys", user), params: { title: 'title' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('key is missing') expect(json_response['error']).to eq('key is missing')
end end
it 'does not create ssh key without title' do it 'does not create ssh key without title' do
post api('/user/keys', user), params: { key: 'some key' } post api('/user/keys', user), params: { key: 'some key' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('title is missing') expect(json_response['error']).to eq('title is missing')
end end
it "does not create ssh key without title" do it "does not create ssh key without title" do
post api("/user/keys", user), params: { key: "somekey" } post api("/user/keys", user), params: { key: "somekey" }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -1650,7 +1650,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1650,7 +1650,7 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/user/keys/#{key.id}", user) delete api("/user/keys/#{key.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.keys.count}.by(-1) end.to change { user.keys.count}.by(-1)
end end
...@@ -1661,7 +1661,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1661,7 +1661,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 404 if key ID not found" do it "returns 404 if key ID not found" do
delete api("/user/keys/42", user) delete api("/user/keys/42", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Key Not Found') expect(json_response['message']).to eq('404 Key Not Found')
end end
...@@ -1669,13 +1669,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1669,13 +1669,13 @@ describe API::Users, :do_not_mock_admin_mode do
user.keys << key user.keys << key
user.save user.save
delete api("/user/keys/#{key.id}") delete api("/user/keys/#{key.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
delete api("/users/keys/ASDF", admin) delete api("/users/keys/ASDF", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -1684,7 +1684,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1684,7 +1684,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns authentication error' do it 'returns authentication error' do
get api('/user/gpg_keys') get api('/user/gpg_keys')
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1695,7 +1695,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1695,7 +1695,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api('/user/gpg_keys', user) get api('/user/gpg_keys', user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first['key']).to eq(gpg_key.key) expect(json_response.first['key']).to eq(gpg_key.key)
...@@ -1717,14 +1717,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1717,14 +1717,14 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/user/gpg_keys/#{gpg_key.id}", user) get api("/user/gpg_keys/#{gpg_key.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['key']).to eq(gpg_key.key) expect(json_response['key']).to eq(gpg_key.key)
end end
it 'returns 404 Not Found within invalid ID' do it 'returns 404 Not Found within invalid ID' do
get api('/user/gpg_keys/42', user) get api('/user/gpg_keys/42', user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
...@@ -1734,14 +1734,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1734,14 +1734,14 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/user/gpg_keys/#{gpg_key.id}", admin) get api("/user/gpg_keys/#{gpg_key.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
it 'returns 404 for invalid ID' do it 'returns 404 for invalid ID' do
get api('/users/gpg_keys/ASDF', admin) get api('/users/gpg_keys/ASDF', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
context 'scopes' do context 'scopes' do
...@@ -1758,20 +1758,20 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1758,20 +1758,20 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
post api('/user/gpg_keys', user), params: key_attrs post api('/user/gpg_keys', user), params: key_attrs
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end.to change { user.gpg_keys.count }.by(1) end.to change { user.gpg_keys.count }.by(1)
end end
it 'returns a 401 error if unauthorized' do it 'returns a 401 error if unauthorized' do
post api('/user/gpg_keys'), params: { key: 'some key' } post api('/user/gpg_keys'), params: { key: 'some key' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'does not create GPG key without key' do it 'does not create GPG key without key' do
post api('/user/gpg_keys', user) post api('/user/gpg_keys', user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('key is missing') expect(json_response['error']).to eq('key is missing')
end end
end end
...@@ -1791,7 +1791,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1791,7 +1791,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 404 if key ID not found' do it 'returns 404 if key ID not found' do
post api('/user/gpg_keys/42/revoke', user) post api('/user/gpg_keys/42/revoke', user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
...@@ -1801,13 +1801,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1801,13 +1801,13 @@ describe API::Users, :do_not_mock_admin_mode do
post api("/user/gpg_keys/#{gpg_key.id}/revoke") post api("/user/gpg_keys/#{gpg_key.id}/revoke")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'returns a 404 for invalid ID' do it 'returns a 404 for invalid ID' do
post api('/users/gpg_keys/ASDF/revoke', admin) post api('/users/gpg_keys/ASDF/revoke', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -1819,14 +1819,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1819,14 +1819,14 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/user/gpg_keys/#{gpg_key.id}", user) delete api("/user/gpg_keys/#{gpg_key.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.gpg_keys.count}.by(-1) end.to change { user.gpg_keys.count}.by(-1)
end end
it 'returns 404 if key ID not found' do it 'returns 404 if key ID not found' do
delete api('/user/gpg_keys/42', user) delete api('/user/gpg_keys/42', user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 GPG Key Not Found') expect(json_response['message']).to eq('404 GPG Key Not Found')
end end
...@@ -1836,13 +1836,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1836,13 +1836,13 @@ describe API::Users, :do_not_mock_admin_mode do
delete api("/user/gpg_keys/#{gpg_key.id}") delete api("/user/gpg_keys/#{gpg_key.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'returns a 404 for invalid ID' do it 'returns a 404 for invalid ID' do
delete api('/users/gpg_keys/ASDF', admin) delete api('/users/gpg_keys/ASDF', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -1850,7 +1850,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1850,7 +1850,7 @@ describe API::Users, :do_not_mock_admin_mode do
context "when unauthenticated" do context "when unauthenticated" do
it "returns authentication error" do it "returns authentication error" do
get api("/user/emails") get api("/user/emails")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -1861,7 +1861,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1861,7 +1861,7 @@ describe API::Users, :do_not_mock_admin_mode do
get api("/user/emails", user) get api("/user/emails", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.first["email"]).to eq(email.email) expect(json_response.first["email"]).to eq(email.email)
...@@ -1881,13 +1881,13 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1881,13 +1881,13 @@ describe API::Users, :do_not_mock_admin_mode do
user.emails << email user.emails << email
user.save user.save
get api("/user/emails/#{email.id}", user) get api("/user/emails/#{email.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response["email"]).to eq(email.email) expect(json_response["email"]).to eq(email.email)
end end
it "returns 404 Not Found within invalid ID" do it "returns 404 Not Found within invalid ID" do
get api("/user/emails/42", user) get api("/user/emails/42", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Email Not Found') expect(json_response['message']).to eq('404 Email Not Found')
end end
...@@ -1896,14 +1896,14 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1896,14 +1896,14 @@ describe API::Users, :do_not_mock_admin_mode do
user.save user.save
admin admin
get api("/user/emails/#{email.id}", admin) get api("/user/emails/#{email.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Email Not Found') expect(json_response['message']).to eq('404 Email Not Found')
end end
it "returns 404 for invalid ID" do it "returns 404 for invalid ID" do
get api("/users/emails/ASDF", admin) get api("/users/emails/ASDF", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
context "scopes" do context "scopes" do
...@@ -1920,18 +1920,18 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1920,18 +1920,18 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
post api("/user/emails", user), params: email_attrs post api("/user/emails", user), params: email_attrs
end.to change { user.emails.count }.by(1) end.to change { user.emails.count }.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
it "returns a 401 error if unauthorized" do it "returns a 401 error if unauthorized" do
post api("/user/emails"), params: { email: 'some email' } post api("/user/emails"), params: { email: 'some email' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "does not create email with invalid email" do it "does not create email with invalid email" do
post api("/user/emails", user), params: {} post api("/user/emails", user), params: {}
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('email is missing') expect(json_response['error']).to eq('email is missing')
end end
end end
...@@ -1944,7 +1944,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1944,7 +1944,7 @@ describe API::Users, :do_not_mock_admin_mode do
expect do expect do
delete api("/user/emails/#{email.id}", user) delete api("/user/emails/#{email.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change { user.emails.count}.by(-1) end.to change { user.emails.count}.by(-1)
end end
...@@ -1955,7 +1955,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1955,7 +1955,7 @@ describe API::Users, :do_not_mock_admin_mode do
it "returns 404 if email ID not found" do it "returns 404 if email ID not found" do
delete api("/user/emails/42", user) delete api("/user/emails/42", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Email Not Found') expect(json_response['message']).to eq('404 Email Not Found')
end end
...@@ -1963,20 +1963,20 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1963,20 +1963,20 @@ describe API::Users, :do_not_mock_admin_mode do
user.emails << email user.emails << email
user.save user.save
delete api("/user/emails/#{email.id}") delete api("/user/emails/#{email.id}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "returns 400 for invalid ID" do it "returns 400 for invalid ID" do
delete api("/user/emails/ASDF", admin) delete api("/user/emails/ASDF", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
context 'activate and deactivate' do context 'activate and deactivate' do
shared_examples '404' do shared_examples '404' do
it 'returns 404' do it 'returns 404' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
end end
...@@ -1986,7 +1986,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1986,7 +1986,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'is not authorized to perform the action' do it 'is not authorized to perform the action' do
post api("/users/#{user.id}/activate", user) post api("/users/#{user.id}/activate", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -1999,7 +1999,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -1999,7 +1999,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'activates a deactivated user' do it 'activates a deactivated user' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
end end
...@@ -2012,7 +2012,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2012,7 +2012,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 201' do it 'returns 201' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
end end
...@@ -2025,7 +2025,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2025,7 +2025,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 403' do it 'returns 403' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated') expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated')
expect(user.reload.state).to eq('blocked') expect(user.reload.state).to eq('blocked')
end end
...@@ -2039,7 +2039,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2039,7 +2039,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 403' do it 'returns 403' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated') expect(json_response['message']).to eq('403 Forbidden - A blocked user must be unblocked to be activated')
expect(user.reload.state).to eq('ldap_blocked') expect(user.reload.state).to eq('ldap_blocked')
end end
...@@ -2060,7 +2060,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2060,7 +2060,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'is not authorized to perform the action' do it 'is not authorized to perform the action' do
post api("/users/#{user.id}/deactivate", user) post api("/users/#{user.id}/deactivate", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -2077,7 +2077,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2077,7 +2077,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'deactivates an active user' do it 'deactivates an active user' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('deactivated') expect(user.reload.state).to eq('deactivated')
end end
end end
...@@ -2090,7 +2090,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2090,7 +2090,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'does not deactivate an active user' do it 'does not deactivate an active user' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq("403 Forbidden - The user you are trying to deactivate has been active in the past #{::User::MINIMUM_INACTIVE_DAYS} days and cannot be deactivated") expect(json_response['message']).to eq("403 Forbidden - The user you are trying to deactivate has been active in the past #{::User::MINIMUM_INACTIVE_DAYS} days and cannot be deactivated")
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
...@@ -2105,7 +2105,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2105,7 +2105,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 201' do it 'returns 201' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('deactivated') expect(user.reload.state).to eq('deactivated')
end end
end end
...@@ -2118,7 +2118,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2118,7 +2118,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 403' do it 'returns 403' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user cannot be deactivated by the API') expect(json_response['message']).to eq('403 Forbidden - A blocked user cannot be deactivated by the API')
expect(user.reload.state).to eq('blocked') expect(user.reload.state).to eq('blocked')
end end
...@@ -2132,7 +2132,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2132,7 +2132,7 @@ describe API::Users, :do_not_mock_admin_mode do
end end
it 'returns 403' do it 'returns 403' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden - A blocked user cannot be deactivated by the API') expect(json_response['message']).to eq('403 Forbidden - A blocked user cannot be deactivated by the API')
expect(user.reload.state).to eq('ldap_blocked') expect(user.reload.state).to eq('ldap_blocked')
end end
...@@ -2156,25 +2156,25 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2156,25 +2156,25 @@ describe API::Users, :do_not_mock_admin_mode do
it 'blocks existing user' do it 'blocks existing user' do
post api("/users/#{user.id}/block", admin) post api("/users/#{user.id}/block", admin)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('blocked') expect(user.reload.state).to eq('blocked')
end end
it 'does not re-block ldap blocked users' do it 'does not re-block ldap blocked users' do
post api("/users/#{ldap_blocked_user.id}/block", admin) post api("/users/#{ldap_blocked_user.id}/block", admin)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') expect(ldap_blocked_user.reload.state).to eq('ldap_blocked')
end end
it 'does not be available for non admin users' do it 'does not be available for non admin users' do
post api("/users/#{user.id}/block", user) post api("/users/#{user.id}/block", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'returns a 404 error if user id not found' do it 'returns a 404 error if user id not found' do
post api('/users/0/block', admin) post api('/users/0/block', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
end end
...@@ -2189,44 +2189,44 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2189,44 +2189,44 @@ describe API::Users, :do_not_mock_admin_mode do
it 'unblocks existing user' do it 'unblocks existing user' do
post api("/users/#{user.id}/unblock", admin) post api("/users/#{user.id}/unblock", admin)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'unblocks a blocked user' do it 'unblocks a blocked user' do
post api("/users/#{blocked_user.id}/unblock", admin) post api("/users/#{blocked_user.id}/unblock", admin)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(blocked_user.reload.state).to eq('active') expect(blocked_user.reload.state).to eq('active')
end end
it 'does not unblock ldap blocked users' do it 'does not unblock ldap blocked users' do
post api("/users/#{ldap_blocked_user.id}/unblock", admin) post api("/users/#{ldap_blocked_user.id}/unblock", admin)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(ldap_blocked_user.reload.state).to eq('ldap_blocked') expect(ldap_blocked_user.reload.state).to eq('ldap_blocked')
end end
it 'does not unblock deactivated users' do it 'does not unblock deactivated users' do
post api("/users/#{deactivated_user.id}/unblock", admin) post api("/users/#{deactivated_user.id}/unblock", admin)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(deactivated_user.reload.state).to eq('deactivated') expect(deactivated_user.reload.state).to eq('deactivated')
end end
it 'is not available for non admin users' do it 'is not available for non admin users' do
post api("/users/#{user.id}/unblock", user) post api("/users/#{user.id}/unblock", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(user.reload.state).to eq('active') expect(user.reload.state).to eq('active')
end end
it 'returns a 404 error if user id not found' do it 'returns a 404 error if user id not found' do
post api('/users/0/block', admin) post api('/users/0/block', admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it "returns a 404 for invalid ID" do it "returns a 404 for invalid ID" do
post api("/users/ASDF/block", admin) post api("/users/ASDF/block", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -2315,7 +2315,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2315,7 +2315,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'has no permission' do it 'has no permission' do
get api("/user/activities", user) get api("/user/activities", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -2367,7 +2367,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2367,7 +2367,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'renders errors when the status was invalid' do it 'renders errors when the status was invalid' do
put api('/user/status', user), params: { emoji: 'does not exist', message: 'hello world' } put api('/user/status', user), params: { emoji: 'does not exist', message: 'hello world' }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['emoji']).to be_present expect(json_response['message']['emoji']).to be_present
end end
...@@ -2389,21 +2389,21 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2389,21 +2389,21 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns a 404 error if user not found' do it 'returns a 404 error if user not found' do
get api("/users/#{not_existing_user_id}/impersonation_tokens", admin) get api("/users/#{not_existing_user_id}/impersonation_tokens", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns a 403 error when authenticated as normal user' do it 'returns a 403 error when authenticated as normal user' do
get api("/users/#{not_existing_user_id}/impersonation_tokens", user) get api("/users/#{not_existing_user_id}/impersonation_tokens", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden') expect(json_response['message']).to eq('403 Forbidden')
end end
it 'returns an array of all impersonated tokens' do it 'returns an array of all impersonated tokens' do
get api("/users/#{user.id}/impersonation_tokens", admin) get api("/users/#{user.id}/impersonation_tokens", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
...@@ -2412,7 +2412,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2412,7 +2412,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns an array of active impersonation tokens if state active' do it 'returns an array of active impersonation tokens if state active' do
get api("/users/#{user.id}/impersonation_tokens?state=active", admin) get api("/users/#{user.id}/impersonation_tokens?state=active", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
...@@ -2422,7 +2422,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2422,7 +2422,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns an array of inactive personal access tokens if active is set to false' do it 'returns an array of inactive personal access tokens if active is set to false' do
get api("/users/#{user.id}/impersonation_tokens?state=inactive", admin) get api("/users/#{user.id}/impersonation_tokens?state=inactive", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_an Array expect(json_response).to be_an Array
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response).to all(include('active' => false)) expect(json_response).to all(include('active' => false))
...@@ -2438,7 +2438,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2438,7 +2438,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns validation error if impersonation token misses some attributes' do it 'returns validation error if impersonation token misses some attributes' do
post api("/users/#{user.id}/impersonation_tokens", admin) post api("/users/#{user.id}/impersonation_tokens", admin)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['error']).to eq('name is missing') expect(json_response['error']).to eq('name is missing')
end end
...@@ -2449,7 +2449,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2449,7 +2449,7 @@ describe API::Users, :do_not_mock_admin_mode do
expires_at: expires_at expires_at: expires_at
} }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
...@@ -2460,7 +2460,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2460,7 +2460,7 @@ describe API::Users, :do_not_mock_admin_mode do
expires_at: expires_at expires_at: expires_at
} }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden') expect(json_response['message']).to eq('403 Forbidden')
end end
...@@ -2473,7 +2473,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2473,7 +2473,7 @@ describe API::Users, :do_not_mock_admin_mode do
impersonation: impersonation impersonation: impersonation
} }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['name']).to eq(name) expect(json_response['name']).to eq(name)
expect(json_response['scopes']).to eq(scopes) expect(json_response['scopes']).to eq(scopes)
expect(json_response['expires_at']).to eq(expires_at) expect(json_response['expires_at']).to eq(expires_at)
...@@ -2493,35 +2493,35 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2493,35 +2493,35 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns 404 error if user not found' do it 'returns 404 error if user not found' do
get api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin) get api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns a 404 error if impersonation token not found' do it 'returns a 404 error if impersonation token not found' do
get api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin) get api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Impersonation Token Not Found') expect(json_response['message']).to eq('404 Impersonation Token Not Found')
end end
it 'returns a 404 error if token is not impersonation token' do it 'returns a 404 error if token is not impersonation token' do
get api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin) get api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Impersonation Token Not Found') expect(json_response['message']).to eq('404 Impersonation Token Not Found')
end end
it 'returns a 403 error when authenticated as normal user' do it 'returns a 403 error when authenticated as normal user' do
get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user) get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden') expect(json_response['message']).to eq('403 Forbidden')
end end
it 'returns an impersonation token' do it 'returns an impersonation token' do
get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin) get api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['token']).not_to be_present expect(json_response['token']).not_to be_present
expect(json_response['impersonation']).to be_truthy expect(json_response['impersonation']).to be_truthy
end end
...@@ -2534,28 +2534,28 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2534,28 +2534,28 @@ describe API::Users, :do_not_mock_admin_mode do
it 'returns a 404 error if user not found' do it 'returns a 404 error if user not found' do
delete api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin) delete api("/users/#{not_existing_user_id}/impersonation_tokens/1", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 User Not Found') expect(json_response['message']).to eq('404 User Not Found')
end end
it 'returns a 404 error if impersonation token not found' do it 'returns a 404 error if impersonation token not found' do
delete api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin) delete api("/users/#{user.id}/impersonation_tokens/#{not_existing_pat_id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Impersonation Token Not Found') expect(json_response['message']).to eq('404 Impersonation Token Not Found')
end end
it 'returns a 404 error if token is not impersonation token' do it 'returns a 404 error if token is not impersonation token' do
delete api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin) delete api("/users/#{user.id}/impersonation_tokens/#{personal_access_token.id}", admin)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response['message']).to eq('404 Impersonation Token Not Found') expect(json_response['message']).to eq('404 Impersonation Token Not Found')
end end
it 'returns a 403 error when authenticated as normal user' do it 'returns a 403 error when authenticated as normal user' do
delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user) delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", user)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response['message']).to eq('403 Forbidden') expect(json_response['message']).to eq('403 Forbidden')
end end
...@@ -2566,7 +2566,7 @@ describe API::Users, :do_not_mock_admin_mode do ...@@ -2566,7 +2566,7 @@ describe API::Users, :do_not_mock_admin_mode do
it 'revokes a impersonation token' do it 'revokes a impersonation token' do
delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin) delete api("/users/#{user.id}/impersonation_tokens/#{impersonation_token.id}", admin)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(impersonation_token.revoked).to be_falsey expect(impersonation_token.revoked).to be_falsey
expect(impersonation_token.reload.revoked).to be_truthy expect(impersonation_token.reload.revoked).to be_truthy
end end
......
...@@ -15,7 +15,7 @@ describe API::Variables do ...@@ -15,7 +15,7 @@ describe API::Variables do
it 'returns project variables' do it 'returns project variables' do
get api("/projects/#{project.id}/variables", user) get api("/projects/#{project.id}/variables", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to be_a(Array) expect(json_response).to be_a(Array)
end end
end end
...@@ -24,7 +24,7 @@ describe API::Variables do ...@@ -24,7 +24,7 @@ describe API::Variables do
it 'does not return project variables' do it 'does not return project variables' do
get api("/projects/#{project.id}/variables", user2) get api("/projects/#{project.id}/variables", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -32,7 +32,7 @@ describe API::Variables do ...@@ -32,7 +32,7 @@ describe API::Variables do
it 'does not return project variables' do it 'does not return project variables' do
get api("/projects/#{project.id}/variables") get api("/projects/#{project.id}/variables")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -42,7 +42,7 @@ describe API::Variables do ...@@ -42,7 +42,7 @@ describe API::Variables do
it 'returns project variable details' do it 'returns project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}", user) get api("/projects/#{project.id}/variables/#{variable.key}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['value']).to eq(variable.value) expect(json_response['value']).to eq(variable.value)
expect(json_response['protected']).to eq(variable.protected?) expect(json_response['protected']).to eq(variable.protected?)
expect(json_response['masked']).to eq(variable.masked?) expect(json_response['masked']).to eq(variable.masked?)
...@@ -52,7 +52,7 @@ describe API::Variables do ...@@ -52,7 +52,7 @@ describe API::Variables do
it 'responds with 404 Not Found if requesting non-existing variable' do it 'responds with 404 Not Found if requesting non-existing variable' do
get api("/projects/#{project.id}/variables/non_existing_variable", user) get api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -60,7 +60,7 @@ describe API::Variables do ...@@ -60,7 +60,7 @@ describe API::Variables do
it 'does not return project variable details' do it 'does not return project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}", user2) get api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -68,7 +68,7 @@ describe API::Variables do ...@@ -68,7 +68,7 @@ describe API::Variables do
it 'does not return project variable details' do it 'does not return project variable details' do
get api("/projects/#{project.id}/variables/#{variable.key}") get api("/projects/#{project.id}/variables/#{variable.key}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -80,7 +80,7 @@ describe API::Variables do ...@@ -80,7 +80,7 @@ describe API::Variables do
post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true, masked: true } post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'PROTECTED_VALUE_2', protected: true, masked: true }
end.to change {project.variables.count}.by(1) end.to change {project.variables.count}.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['key']).to eq('TEST_VARIABLE_2')
expect(json_response['value']).to eq('PROTECTED_VALUE_2') expect(json_response['value']).to eq('PROTECTED_VALUE_2')
expect(json_response['protected']).to be_truthy expect(json_response['protected']).to be_truthy
...@@ -93,7 +93,7 @@ describe API::Variables do ...@@ -93,7 +93,7 @@ describe API::Variables do
post api("/projects/#{project.id}/variables", user), params: { variable_type: 'file', key: 'TEST_VARIABLE_2', value: 'VALUE_2' } post api("/projects/#{project.id}/variables", user), params: { variable_type: 'file', key: 'TEST_VARIABLE_2', value: 'VALUE_2' }
end.to change {project.variables.count}.by(1) end.to change {project.variables.count}.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['key']).to eq('TEST_VARIABLE_2')
expect(json_response['value']).to eq('VALUE_2') expect(json_response['value']).to eq('VALUE_2')
expect(json_response['protected']).to be_falsey expect(json_response['protected']).to be_falsey
...@@ -106,7 +106,7 @@ describe API::Variables do ...@@ -106,7 +106,7 @@ describe API::Variables do
post api("/projects/#{project.id}/variables", user), params: { key: variable.key, value: 'VALUE_2' } post api("/projects/#{project.id}/variables", user), params: { key: variable.key, value: 'VALUE_2' }
end.to change {project.variables.count}.by(0) end.to change {project.variables.count}.by(0)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it 'creates variable with a specific environment scope' do it 'creates variable with a specific environment scope' do
...@@ -114,7 +114,7 @@ describe API::Variables do ...@@ -114,7 +114,7 @@ describe API::Variables do
post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'VALUE_2', environment_scope: 'review/*' } post api("/projects/#{project.id}/variables", user), params: { key: 'TEST_VARIABLE_2', value: 'VALUE_2', environment_scope: 'review/*' }
end.to change { project.variables.reload.count }.by(1) end.to change { project.variables.reload.count }.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['key']).to eq('TEST_VARIABLE_2') expect(json_response['key']).to eq('TEST_VARIABLE_2')
expect(json_response['value']).to eq('VALUE_2') expect(json_response['value']).to eq('VALUE_2')
expect(json_response['environment_scope']).to eq('review/*') expect(json_response['environment_scope']).to eq('review/*')
...@@ -127,7 +127,7 @@ describe API::Variables do ...@@ -127,7 +127,7 @@ describe API::Variables do
post api("/projects/#{project.id}/variables", user), params: { key: variable.key, value: 'VALUE_2', environment_scope: 'review/*' } post api("/projects/#{project.id}/variables", user), params: { key: variable.key, value: 'VALUE_2', environment_scope: 'review/*' }
end.to change { project.variables.reload.count }.by(1) end.to change { project.variables.reload.count }.by(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['key']).to eq(variable.key) expect(json_response['key']).to eq(variable.key)
expect(json_response['value']).to eq('VALUE_2') expect(json_response['value']).to eq('VALUE_2')
expect(json_response['environment_scope']).to eq('review/*') expect(json_response['environment_scope']).to eq('review/*')
...@@ -138,7 +138,7 @@ describe API::Variables do ...@@ -138,7 +138,7 @@ describe API::Variables do
it 'does not create variable' do it 'does not create variable' do
post api("/projects/#{project.id}/variables", user2) post api("/projects/#{project.id}/variables", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -146,7 +146,7 @@ describe API::Variables do ...@@ -146,7 +146,7 @@ describe API::Variables do
it 'does not create variable' do it 'does not create variable' do
post api("/projects/#{project.id}/variables") post api("/projects/#{project.id}/variables")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -161,7 +161,7 @@ describe API::Variables do ...@@ -161,7 +161,7 @@ describe API::Variables do
updated_variable = project.variables.reload.first updated_variable = project.variables.reload.first
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(value_before).to eq(variable.value) expect(value_before).to eq(variable.value)
expect(updated_variable.value).to eq('VALUE_1_UP') expect(updated_variable.value).to eq('VALUE_1_UP')
expect(updated_variable).to be_protected expect(updated_variable).to be_protected
...@@ -171,7 +171,7 @@ describe API::Variables do ...@@ -171,7 +171,7 @@ describe API::Variables do
it 'responds with 404 Not Found if requesting non-existing variable' do it 'responds with 404 Not Found if requesting non-existing variable' do
put api("/projects/#{project.id}/variables/non_existing_variable", user) put api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -179,7 +179,7 @@ describe API::Variables do ...@@ -179,7 +179,7 @@ describe API::Variables do
it 'does not update variable' do it 'does not update variable' do
put api("/projects/#{project.id}/variables/#{variable.key}", user2) put api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -187,7 +187,7 @@ describe API::Variables do ...@@ -187,7 +187,7 @@ describe API::Variables do
it 'does not update variable' do it 'does not update variable' do
put api("/projects/#{project.id}/variables/#{variable.key}") put api("/projects/#{project.id}/variables/#{variable.key}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
...@@ -198,14 +198,14 @@ describe API::Variables do ...@@ -198,14 +198,14 @@ describe API::Variables do
expect do expect do
delete api("/projects/#{project.id}/variables/#{variable.key}", user) delete api("/projects/#{project.id}/variables/#{variable.key}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end.to change {project.variables.count}.by(-1) end.to change {project.variables.count}.by(-1)
end end
it 'responds with 404 Not Found if requesting non-existing variable' do it 'responds with 404 Not Found if requesting non-existing variable' do
delete api("/projects/#{project.id}/variables/non_existing_variable", user) delete api("/projects/#{project.id}/variables/non_existing_variable", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -213,7 +213,7 @@ describe API::Variables do ...@@ -213,7 +213,7 @@ describe API::Variables do
it 'does not delete variable' do it 'does not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.key}", user2) delete api("/projects/#{project.id}/variables/#{variable.key}", user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -221,7 +221,7 @@ describe API::Variables do ...@@ -221,7 +221,7 @@ describe API::Variables do
it 'does not delete variable' do it 'does not delete variable' do
delete api("/projects/#{project.id}/variables/#{variable.key}") delete api("/projects/#{project.id}/variables/#{variable.key}")
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
end end
......
...@@ -8,7 +8,7 @@ describe API::Version do ...@@ -8,7 +8,7 @@ describe API::Version do
it 'returns authentication error' do it 'returns authentication error' do
get api('/version') get api('/version')
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
end end
...@@ -51,13 +51,13 @@ describe API::Version do ...@@ -51,13 +51,13 @@ describe API::Version do
it 'returns authorization error' do it 'returns authorization error' do
get api('/version', personal_access_token: personal_access_token) get api('/version', personal_access_token: personal_access_token)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
def expect_version def expect_version
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['version']).to eq(Gitlab::VERSION) expect(json_response['version']).to eq(Gitlab::VERSION)
expect(json_response['revision']).to eq(Gitlab.revision) expect(json_response['revision']).to eq(Gitlab.revision)
end end
......
...@@ -32,7 +32,7 @@ describe API::Wikis do ...@@ -32,7 +32,7 @@ describe API::Wikis do
it 'returns the list of wiki pages without content' do it 'returns the list of wiki pages without content' do
get api(url, user) get api(url, user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
json_response.each_with_index do |page, index| json_response.each_with_index do |page, index|
...@@ -45,7 +45,7 @@ describe API::Wikis do ...@@ -45,7 +45,7 @@ describe API::Wikis do
it 'returns the list of wiki pages with content' do it 'returns the list of wiki pages with content' do
get api(url, user), params: { with_content: 1 } get api(url, user), params: { with_content: 1 }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(2) expect(json_response.size).to eq(2)
json_response.each_with_index do |page, index| json_response.each_with_index do |page, index|
...@@ -60,14 +60,14 @@ describe API::Wikis do ...@@ -60,14 +60,14 @@ describe API::Wikis do
it 'return the empty list of wiki pages' do it 'return the empty list of wiki pages' do
get api(url, user) get api(url, user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(0) expect(json_response.size).to eq(0)
end end
end end
shared_examples_for 'returns wiki page' do shared_examples_for 'returns wiki page' do
it 'returns the wiki page' do it 'returns the wiki page' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(4) expect(json_response.size).to eq(4)
expect(json_response.keys).to match_array(expected_keys_with_content) expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(page.content) expect(json_response['content']).to eq(page.content)
...@@ -80,7 +80,7 @@ describe API::Wikis do ...@@ -80,7 +80,7 @@ describe API::Wikis do
it 'creates the wiki page' do it 'creates the wiki page' do
post(api(url, user), params: payload) post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response.size).to eq(4) expect(json_response.size).to eq(4)
expect(json_response.keys).to match_array(expected_keys_with_content) expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(payload[:content]) expect(json_response['content']).to eq(payload[:content])
...@@ -95,7 +95,7 @@ describe API::Wikis do ...@@ -95,7 +95,7 @@ describe API::Wikis do
post(api(url, user), params: payload) post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['error']).to eq("#{part} is missing") expect(json_response['error']).to eq("#{part} is missing")
end end
...@@ -106,7 +106,7 @@ describe API::Wikis do ...@@ -106,7 +106,7 @@ describe API::Wikis do
it 'updates the wiki page' do it 'updates the wiki page' do
put(api(url, user), params: payload) put(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to eq(4) expect(json_response.size).to eq(4)
expect(json_response.keys).to match_array(expected_keys_with_content) expect(json_response.keys).to match_array(expected_keys_with_content)
expect(json_response['content']).to eq(payload[:content]) expect(json_response['content']).to eq(payload[:content])
...@@ -120,14 +120,14 @@ describe API::Wikis do ...@@ -120,14 +120,14 @@ describe API::Wikis do
put(api(url, user), params: payload) put(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
end end
shared_examples_for '403 Forbidden' do shared_examples_for '403 Forbidden' do
it 'returns 403 Forbidden' do it 'returns 403 Forbidden' do
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['message']).to eq('403 Forbidden') expect(json_response['message']).to eq('403 Forbidden')
end end
...@@ -135,7 +135,7 @@ describe API::Wikis do ...@@ -135,7 +135,7 @@ describe API::Wikis do
shared_examples_for '404 Wiki Page Not Found' do shared_examples_for '404 Wiki Page Not Found' do
it 'returns 404 Wiki Page Not Found' do it 'returns 404 Wiki Page Not Found' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['message']).to eq('404 Wiki Page Not Found') expect(json_response['message']).to eq('404 Wiki Page Not Found')
end end
...@@ -143,7 +143,7 @@ describe API::Wikis do ...@@ -143,7 +143,7 @@ describe API::Wikis do
shared_examples_for '404 Project Not Found' do shared_examples_for '404 Project Not Found' do
it 'returns 404 Project Not Found' do it 'returns 404 Project Not Found' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['message']).to eq('404 Project Not Found') expect(json_response['message']).to eq('404 Project Not Found')
end end
...@@ -151,7 +151,7 @@ describe API::Wikis do ...@@ -151,7 +151,7 @@ describe API::Wikis do
shared_examples_for '204 No Content' do shared_examples_for '204 No Content' do
it 'returns 204 No Content' do it 'returns 204 No Content' do
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end end
end end
...@@ -161,7 +161,7 @@ describe API::Wikis do ...@@ -161,7 +161,7 @@ describe API::Wikis do
workhorse_post_with_file(api(url, user), file_key: :file, params: payload) workhorse_post_with_file(api(url, user), file_key: :file, params: payload)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response).to eq result_hash.deep_stringify_keys expect(json_response).to eq result_hash.deep_stringify_keys
end end
...@@ -170,7 +170,7 @@ describe API::Wikis do ...@@ -170,7 +170,7 @@ describe API::Wikis do
post(api(url, user), params: payload) post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['error']).to eq('file is missing') expect(json_response['error']).to eq('file is missing')
end end
...@@ -180,7 +180,7 @@ describe API::Wikis do ...@@ -180,7 +180,7 @@ describe API::Wikis do
post(api(url, user), params: payload) post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.size).to eq(1) expect(json_response.size).to eq(1)
expect(json_response['error']).to eq('file is invalid') expect(json_response['error']).to eq('file is invalid')
end end
...@@ -190,7 +190,7 @@ describe API::Wikis do ...@@ -190,7 +190,7 @@ describe API::Wikis do
post(api(url, user), params: payload) post(api(url, user), params: payload)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response).to eq result_hash.deep_stringify_keys expect(json_response).to eq result_hash.deep_stringify_keys
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