Commit 75087619 authored by Peter Leitzen's avatar Peter Leitzen Committed by Jan Provaznik

Add cop HaveGitlabHttpStatus in EE shared examples

55 files inspected, 41 offenses detected, 41 offenses corrected
parent ad66b824
...@@ -347,6 +347,7 @@ RSpec/HaveGitlabHttpStatus: ...@@ -347,6 +347,7 @@ RSpec/HaveGitlabHttpStatus:
Enabled: true Enabled: true
Include: Include:
- 'spec/support/shared_examples/**/*' - 'spec/support/shared_examples/**/*'
- 'ee/spec/support/shared_examples/**/*'
Style/MultilineWhenThen: Style/MultilineWhenThen:
Enabled: false Enabled: false
......
...@@ -30,7 +30,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do ...@@ -30,7 +30,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.length).to eq 2 expect(json_response.length).to eq 2
expect(json_response.first['id']).to be(critical_vulnerability.id) expect(json_response.first['id']).to be(critical_vulnerability.id)
expect(response).to match_response_schema('vulnerabilities/occurrence_list', dir: 'ee') expect(response).to match_response_schema('vulnerabilities/occurrence_list', dir: 'ee')
...@@ -130,7 +130,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do ...@@ -130,7 +130,7 @@ RSpec.shared_examples ProjectVulnerabilityFindingsActions do
end end
it 'returns vulnerability findings counts for all report types' do it 'returns vulnerability findings counts for all report types' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['high']).to eq(3) expect(json_response['high']).to eq(3)
expect(json_response['low']).to eq(2) expect(json_response['low']).to eq(2)
expect(json_response['medium']).to eq(2) expect(json_response['medium']).to eq(2)
......
...@@ -16,7 +16,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do ...@@ -16,7 +16,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do
security_dashboard_action security_dashboard_action
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -31,7 +31,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do ...@@ -31,7 +31,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do
security_dashboard_action security_dashboard_action
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -41,7 +41,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do ...@@ -41,7 +41,7 @@ RSpec.shared_examples SecurityDashboardsPermissions do
security_dashboard_action security_dashboard_action
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
end end
......
...@@ -8,14 +8,14 @@ RSpec.shared_examples 'multiple issue boards show' do ...@@ -8,14 +8,14 @@ RSpec.shared_examples 'multiple issue boards show' do
it 'lets user view board1' do it 'lets user view board1' do
show(board1) show(board1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:board)).to eq(board1) expect(assigns(:board)).to eq(board1)
end end
it 'lets user view board2' do it 'lets user view board2' do
show(board2) show(board2)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:board)).to eq(board2) expect(assigns(:board)).to eq(board2)
end end
end end
...@@ -28,7 +28,7 @@ RSpec.shared_examples 'multiple issue boards show' do ...@@ -28,7 +28,7 @@ RSpec.shared_examples 'multiple issue boards show' do
it 'let user view the default shown board' do it 'let user view the default shown board' do
show(board2) show(board2)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:board)).to eq(board2) expect(assigns(:board)).to eq(board2)
end end
...@@ -36,9 +36,9 @@ RSpec.shared_examples 'multiple issue boards show' do ...@@ -36,9 +36,9 @@ RSpec.shared_examples 'multiple issue boards show' do
show(board1) show(board1)
if parent.is_a?(Project) if parent.is_a?(Project)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
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
......
...@@ -35,10 +35,10 @@ RSpec.shared_examples 'redirects to last visited board' do ...@@ -35,10 +35,10 @@ RSpec.shared_examples 'redirects to last visited board' do
if parent.is_a?(Group) if parent.is_a?(Group)
expect(response).to render_template :index expect(response).to render_template :index
expect(response.content_type).to eq 'text/html' expect(response.content_type).to eq 'text/html'
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
else else
expect(response.content_type).to eq 'text/html' expect(response.content_type).to eq 'text/html'
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(:found)
end end
end end
end end
......
...@@ -20,7 +20,7 @@ RSpec.shared_examples 'Insights page' do ...@@ -20,7 +20,7 @@ RSpec.shared_examples 'Insights page' do
it 'has correct title' do it 'has correct title' do
visit route visit route
expect(page).to have_gitlab_http_status(200) expect(page).to have_gitlab_http_status(:ok)
expect(page).to have_content('Insights') expect(page).to have_content('Insights')
end end
...@@ -52,7 +52,7 @@ RSpec.shared_examples 'Insights page' do ...@@ -52,7 +52,7 @@ RSpec.shared_examples 'Insights page' do
it 'returns 404' do it 'returns 404' do
visit route visit route
expect(page).to have_gitlab_http_status(404) expect(page).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -66,7 +66,7 @@ RSpec.shared_examples 'Insights page' do ...@@ -66,7 +66,7 @@ RSpec.shared_examples 'Insights page' do
it 'returns 404' do it 'returns 404' do
visit route visit route
expect(page).to have_gitlab_http_status(404) expect(page).to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -6,7 +6,7 @@ RSpec.shared_examples 'assignee board list' do ...@@ -6,7 +6,7 @@ RSpec.shared_examples 'assignee board list' do
other_user = create(:user) other_user = create(:user)
post api(url, user), params: { assignee_id: other_user.id } post api(url, user), params: { assignee_id: other_user.id }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.dig('message', 'error')).to eq('User not found!') expect(json_response.dig('message', 'error')).to eq('User not found!')
end end
...@@ -15,7 +15,7 @@ RSpec.shared_examples 'assignee board list' do ...@@ -15,7 +15,7 @@ RSpec.shared_examples 'assignee board list' do
post api(url, user), params: { assignee_id: user.id } post api(url, user), params: { assignee_id: user.id }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.dig('message', 'list_type')) expect(json_response.dig('message', 'list_type'))
.to contain_exactly('Assignee lists not available with your current license') .to contain_exactly('Assignee lists not available with your current license')
end end
...@@ -25,7 +25,7 @@ RSpec.shared_examples 'assignee board list' do ...@@ -25,7 +25,7 @@ RSpec.shared_examples 'assignee board list' do
post api(url, user), params: { assignee_id: user.id } post api(url, user), params: { assignee_id: user.id }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response.dig('assignee', 'id')).to eq(user.id) expect(json_response.dig('assignee', 'id')).to eq(user.id)
end end
end end
......
...@@ -6,7 +6,7 @@ RSpec.shared_examples 'milestone board list' do ...@@ -6,7 +6,7 @@ RSpec.shared_examples 'milestone board list' do
other_milestone = create(:milestone) other_milestone = create(:milestone)
post api(url, user), params: { milestone_id: other_milestone.id } post api(url, user), params: { milestone_id: other_milestone.id }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.dig('message', 'error')).to eq('Milestone not found!') expect(json_response.dig('message', 'error')).to eq('Milestone not found!')
end end
...@@ -15,7 +15,7 @@ RSpec.shared_examples 'milestone board list' do ...@@ -15,7 +15,7 @@ RSpec.shared_examples 'milestone board list' do
post api(url, user), params: { milestone_id: milestone.id } post api(url, user), params: { milestone_id: milestone.id }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response.dig('message', 'list_type')) expect(json_response.dig('message', 'list_type'))
.to contain_exactly('Milestone lists not available with your current license') .to contain_exactly('Milestone lists not available with your current license')
end end
...@@ -25,7 +25,7 @@ RSpec.shared_examples 'milestone board list' do ...@@ -25,7 +25,7 @@ RSpec.shared_examples 'milestone board list' do
post api(url, user), params: { milestone_id: milestone.id } post api(url, user), params: { milestone_id: milestone.id }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response.dig('milestone', 'id')).to eq(milestone.id) expect(json_response.dig('milestone', 'id')).to eq(milestone.id)
end end
end end
......
...@@ -7,7 +7,7 @@ RSpec.shared_examples 'group and project milestone burndowns' do |route_definiti ...@@ -7,7 +7,7 @@ RSpec.shared_examples 'group and project milestone burndowns' do |route_definiti
it 'returns burndown events list' do it 'returns burndown events list' do
get api(resource_route, user) get api(resource_route, user)
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['created_at'].to_time).to eq(Date.today.middle_of_day) expect(json_response.first['created_at'].to_time).to eq(Date.today.middle_of_day)
expect(json_response.first['weight']).to eq(5) expect(json_response.first['weight']).to eq(5)
...@@ -22,7 +22,7 @@ RSpec.shared_examples 'group and project milestone burndowns' do |route_definiti ...@@ -22,7 +22,7 @@ RSpec.shared_examples 'group and project milestone burndowns' do |route_definiti
get api(resource_route, outside_user) get api(resource_route, outside_user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -13,7 +13,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition| ...@@ -13,7 +13,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition|
it 'creates a board' do it 'creates a board' do
post api(root_url, user), params: { name: "new board" } post api(root_url, user), params: { name: "new board" }
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/board', dir: "ee") expect(response).to match_response_schema('public_api/v4/board', dir: "ee")
end end
...@@ -25,7 +25,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition| ...@@ -25,7 +25,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition|
it 'updates a board' do it 'updates a board' do
put api(url, user), params: { name: 'new name', weight: 4, labels: 'foo, bar' } put api(url, user), params: { name: 'new name', weight: 4, labels: 'foo, bar' }
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/board', dir: "ee") expect(response).to match_response_schema('public_api/v4/board', dir: "ee")
...@@ -43,14 +43,14 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition| ...@@ -43,14 +43,14 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition|
.and not_change { board.reload.weight } .and not_change { board.reload.weight }
.and not_change { board.reload.labels.map(&:title).sort } .and not_change { board.reload.labels.map(&:title).sort }
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/board', dir: "ee") expect(response).to match_response_schema('public_api/v4/board', dir: "ee")
end end
it 'allows removing optional attributes' do it 'allows removing optional attributes' do
put api(url, user), params: { name: 'new name', assignee_id: nil, milestone_id: nil, weight: nil, labels: nil } put api(url, user), params: { name: 'new name', assignee_id: nil, milestone_id: nil, weight: nil, labels: nil }
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/board', dir: "ee") expect(response).to match_response_schema('public_api/v4/board', dir: "ee")
board.reload board.reload
...@@ -69,7 +69,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition| ...@@ -69,7 +69,7 @@ RSpec.shared_examples 'multiple and scoped issue boards' do |route_definition|
it 'deletes a board' do it 'deletes a board' do
delete api(url, user) delete api(url, user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end end
end end
end end
......
...@@ -13,7 +13,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do ...@@ -13,7 +13,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do
it 'returns 400 status' do it 'returns 400 status' do
post api(url, current_user) post api(url, current_user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -21,7 +21,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do ...@@ -21,7 +21,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do
it 'returns 403' do it 'returns 403' do
post api(url, user2), params: params post api(url, user2), params: params
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -29,7 +29,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do ...@@ -29,7 +29,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do
it 'returns 201 status' do it 'returns 201 status' do
post api(url, current_user), params: params post api(url, current_user), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(response).to match_response_schema(schema, dir: 'ee') expect(response).to match_response_schema(schema, dir: 'ee')
end end
...@@ -68,7 +68,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do ...@@ -68,7 +68,7 @@ RSpec.shared_examples 'an API endpoint for creating project approval rule' do
post api(url, current_user), params: params.merge(name: rule_name) post api(url, current_user), params: params.merge(name: rule_name)
end.to change { ApprovalProjectRule.report_approver.count }.from(0).to(1) end.to change { ApprovalProjectRule.report_approver.count }.from(0).to(1)
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
end end
end end
end end
...@@ -109,7 +109,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do ...@@ -109,7 +109,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do
put api(url, current_user), params: { users: [], groups: [] }.to_json, headers: { CONTENT_TYPE: 'application/json' } put api(url, current_user), params: { users: [], groups: [] }.to_json, headers: { CONTENT_TYPE: 'application/json' }
end.to change { approval_rule.users.count + approval_rule.groups.count }.from(2).to(0) end.to change { approval_rule.users.count + approval_rule.groups.count }.from(2).to(0)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema(schema, dir: 'ee') expect(response).to match_response_schema(schema, dir: 'ee')
end end
end end
...@@ -123,7 +123,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do ...@@ -123,7 +123,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do
expect(approval_rule.users).to contain_exactly(approver) expect(approval_rule.users).to contain_exactly(approver)
expect(approval_rule.groups).to be_empty expect(approval_rule.groups).to be_empty
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -149,7 +149,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do ...@@ -149,7 +149,7 @@ RSpec.shared_examples 'an API endpoint for updating project approval rule' do
put api(url, user2), params: { users: [], groups: [] }.to_json, headers: { CONTENT_TYPE: 'application/json' } put api(url, user2), params: { users: [], groups: [] }.to_json, headers: { CONTENT_TYPE: 'application/json' }
end.not_to change { approval_rule.approvers.size } end.not_to change { approval_rule.approvers.size }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -159,7 +159,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do ...@@ -159,7 +159,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do
delete api(url, user) delete api(url, user)
expect(ApprovalProjectRule.exists?(id: approval_rule.id)).to eq(false) expect(ApprovalProjectRule.exists?(id: approval_rule.id)).to eq(false)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
end end
context 'when approval rule not found' do context 'when approval rule not found' do
...@@ -169,7 +169,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do ...@@ -169,7 +169,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do
it 'returns not found' do it 'returns not found' do
delete api(url, user) delete api(url, user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -177,7 +177,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do ...@@ -177,7 +177,7 @@ RSpec.shared_examples 'an API endpoint for deleting project approval rule' do
it 'returns forbidden' do it 'returns forbidden' do
delete api(url, user2) delete api(url, user2)
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -9,7 +9,7 @@ RSpec.shared_examples 'forbids access to vulnerability API endpoint in case of d ...@@ -9,7 +9,7 @@ RSpec.shared_examples 'forbids access to vulnerability API endpoint in case of d
it 'responds with "not found"' do it 'responds with "not found"' do
subject subject
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -21,7 +21,7 @@ RSpec.shared_examples 'forbids access to vulnerability API endpoint in case of d ...@@ -21,7 +21,7 @@ RSpec.shared_examples 'forbids access to vulnerability API endpoint in case of d
it 'responds with 403 Forbidden' do it 'responds with 403 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
...@@ -32,6 +32,6 @@ RSpec.shared_examples 'responds with "not found" for an unknown vulnerability ID ...@@ -32,6 +32,6 @@ RSpec.shared_examples 'responds with "not found" for an unknown vulnerability ID
it do it do
subject subject
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
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