Commit ee5b6d70 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'pl-rubocop-have-gitlab-http-status-spec-support-shared-examples' into 'master'

Enable cop HaveGitlabHttpStatus in shared examples

See merge request gitlab-org/gitlab!23220
parents 7d903519 bebfcd80
...@@ -344,7 +344,9 @@ RSpec/UnspecifiedException: ...@@ -344,7 +344,9 @@ RSpec/UnspecifiedException:
Enabled: false Enabled: false
RSpec/HaveGitlabHttpStatus: RSpec/HaveGitlabHttpStatus:
Enabled: false Enabled: true
Include:
- 'spec/support/shared_examples/**/*'
Style/MultilineWhenThen: Style/MultilineWhenThen:
Enabled: false Enabled: false
......
...@@ -16,7 +16,7 @@ shared_examples 'disabled when using an external authorization service' do ...@@ -16,7 +16,7 @@ shared_examples 'disabled when using an external authorization service' do
subject subject
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -37,6 +37,6 @@ shared_examples 'unauthorized when external service denies access' do ...@@ -37,6 +37,6 @@ shared_examples 'unauthorized when external service denies access' do
subject subject
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
...@@ -11,7 +11,7 @@ shared_examples 'paginated collection' do ...@@ -11,7 +11,7 @@ shared_examples 'paginated collection' do
it 'renders a page number that is not ouf of range' do it 'renders a page number that is not ouf of range' do
get action, params: params.merge(page: last_page) get action, params: params.merge(page: last_page)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it 'redirects to last_page if page number is larger than number of pages' do it 'redirects to last_page if page number is larger than number of pages' do
......
...@@ -51,7 +51,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -51,7 +51,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
context 'and lfs uses object storage' do context 'and lfs uses object storage' do
...@@ -65,7 +65,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -65,7 +65,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
it 'responds with redirect to file' do it 'responds with redirect to file' do
subject subject
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(:found)
expect(response.location).to include(lfs_object.reload.file.path) expect(response.location).to include(lfs_object.reload.file.path)
end end
...@@ -84,7 +84,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -84,7 +84,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
it 'does not serve the file' do it 'does not serve the file' do
subject subject
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -97,7 +97,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -97,7 +97,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
it 'does not serve the file if no members are linked to the LfsObject' do it 'does not serve the file if no members are linked to the LfsObject' do
subject subject
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'serves the file when the fork network root is linked to the LfsObject' do it 'serves the file when the fork network root is linked to the LfsObject' do
...@@ -105,7 +105,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -105,7 +105,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it 'serves the file when the fork network member is linked to the LfsObject' do it 'serves the file when the fork network member is linked to the LfsObject' do
...@@ -113,7 +113,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -113,7 +113,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -154,7 +154,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| ...@@ -154,7 +154,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}|
subject subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8') expect(response.header['Content-Type']).to eq('text/plain; charset=utf-8')
expect(response.header['Content-Disposition']) expect(response.header['Content-Disposition'])
.to eq('inline') .to eq('inline')
......
...@@ -12,13 +12,13 @@ shared_examples 'todos actions' do ...@@ -12,13 +12,13 @@ shared_examples 'todos actions' do
post_create post_create
end.to change { user.todos.count }.by(1) end.to change { user.todos.count }.by(1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it 'returns todo path and pending count' do it 'returns todo path and pending count' do
post_create post_create
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['count']).to eq 1 expect(json_response['count']).to eq 1
expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}}) expect(json_response['delete_path']).to match(%r{/dashboard/todos/\d{1}})
end end
...@@ -31,7 +31,7 @@ shared_examples 'todos actions' do ...@@ -31,7 +31,7 @@ shared_examples 'todos actions' do
post_create post_create
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'does not create todo when user is not logged in' do it 'does not create todo when user is not logged in' do
...@@ -39,7 +39,7 @@ shared_examples 'todos actions' do ...@@ -39,7 +39,7 @@ shared_examples 'todos actions' do
post_create post_create
end.to change { user.todos.count }.by(0) end.to change { user.todos.count }.by(0)
expect(response).to have_gitlab_http_status(302) expect(response).to have_gitlab_http_status(:found)
end end
end end
end end
...@@ -27,7 +27,7 @@ shared_examples 'handle uploads' do ...@@ -27,7 +27,7 @@ shared_examples 'handle uploads' do
it "returns an error" do it "returns an error" do
post :create, params: params, format: :json post :create, params: params, format: :json
expect(response).to have_gitlab_http_status(422) expect(response).to have_gitlab_http_status(:unprocessable_entity)
end end
end end
...@@ -84,7 +84,7 @@ shared_examples 'handle uploads' do ...@@ -84,7 +84,7 @@ shared_examples 'handle uploads' do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -110,7 +110,7 @@ shared_examples 'handle uploads' do ...@@ -110,7 +110,7 @@ shared_examples 'handle uploads' do
it "responds with status 200" do it "responds with status 200" do
show_upload show_upload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -123,7 +123,7 @@ shared_examples 'handle uploads' do ...@@ -123,7 +123,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -135,7 +135,7 @@ shared_examples 'handle uploads' do ...@@ -135,7 +135,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -149,7 +149,7 @@ shared_examples 'handle uploads' do ...@@ -149,7 +149,7 @@ shared_examples 'handle uploads' do
it "responds with status 200" do it "responds with status 200" do
show_upload show_upload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -161,7 +161,7 @@ shared_examples 'handle uploads' do ...@@ -161,7 +161,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -182,7 +182,7 @@ shared_examples 'handle uploads' do ...@@ -182,7 +182,7 @@ shared_examples 'handle uploads' do
it "responds with status 200" do it "responds with status 200" do
show_upload show_upload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -226,7 +226,7 @@ shared_examples 'handle uploads' do ...@@ -226,7 +226,7 @@ shared_examples 'handle uploads' do
it "responds with status 200" do it "responds with status 200" do
show_upload show_upload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -238,7 +238,7 @@ shared_examples 'handle uploads' do ...@@ -238,7 +238,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -253,7 +253,7 @@ shared_examples 'handle uploads' do ...@@ -253,7 +253,7 @@ shared_examples 'handle uploads' do
it "responds with status 200" do it "responds with status 200" do
show_upload show_upload
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -265,7 +265,7 @@ shared_examples 'handle uploads' do ...@@ -265,7 +265,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -278,7 +278,7 @@ shared_examples 'handle uploads' do ...@@ -278,7 +278,7 @@ shared_examples 'handle uploads' do
it "responds with status 404" do it "responds with status 404" do
show_upload show_upload
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -321,7 +321,7 @@ shared_examples 'handle uploads authorize' do ...@@ -321,7 +321,7 @@ shared_examples 'handle uploads authorize' do
end end
it 'responds with status 200' do it 'responds with status 200' do
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
it 'uses the gitlab-workhorse content type' do it 'uses the gitlab-workhorse content type' do
......
...@@ -6,7 +6,7 @@ shared_examples 'discussions provider' do ...@@ -6,7 +6,7 @@ shared_examples 'discussions provider' do
it 'returns the expected discussions' do it 'returns the expected discussions' do
get :discussions, params: { namespace_id: project.namespace, project_id: project, id: requested_iid } get :discussions, params: { namespace_id: project.namespace, project_id: project, id: requested_iid }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('entities/discussions') expect(response).to match_response_schema('entities/discussions')
expect(json_response.size).to eq(expected_discussion_count) expect(json_response.size).to eq(expected_discussion_count)
......
...@@ -13,7 +13,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -13,7 +13,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'does not filter by custom attributes' do it 'does not filter by custom attributes' do
get api("/#{attributable_name}", user), params: { custom_attributes: { foo: 'foo', bar: 'bar' } } get api("/#{attributable_name}", user), params: { custom_attributes: { foo: 'foo', bar: 'bar' } }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to be 2 expect(json_response.size).to be 2
expect(json_response.map { |r| r['id'] }).to contain_exactly attributable.id, other_attributable.id expect(json_response.map { |r| r['id'] }).to contain_exactly attributable.id, other_attributable.id
end end
...@@ -23,7 +23,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -23,7 +23,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'filters by custom attributes' do it 'filters by custom attributes' do
get api("/#{attributable_name}", admin), params: { custom_attributes: { foo: 'foo', bar: 'bar' } } get api("/#{attributable_name}", admin), params: { custom_attributes: { foo: 'foo', bar: 'bar' } }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to be 1 expect(json_response.size).to be 1
expect(json_response.first['id']).to eq attributable.id expect(json_response.first['id']).to eq attributable.id
end end
...@@ -39,7 +39,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -39,7 +39,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'does not include custom attributes' do it 'does not include custom attributes' do
get api("/#{attributable_name}", user), params: { with_custom_attributes: true } get api("/#{attributable_name}", user), params: { with_custom_attributes: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to be 2 expect(json_response.size).to be 2
expect(json_response.first).not_to include 'custom_attributes' expect(json_response.first).not_to include 'custom_attributes'
end end
...@@ -49,7 +49,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -49,7 +49,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'does not include custom attributes by default' do it 'does not include custom attributes by default' do
get api("/#{attributable_name}", admin) get api("/#{attributable_name}", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to be 2 expect(json_response.size).to be 2
expect(json_response.first).not_to include 'custom_attributes' expect(json_response.first).not_to include 'custom_attributes'
expect(json_response.second).not_to include 'custom_attributes' expect(json_response.second).not_to include 'custom_attributes'
...@@ -58,7 +58,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -58,7 +58,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'includes custom attributes if requested' do it 'includes custom attributes if requested' do
get api("/#{attributable_name}", admin), params: { with_custom_attributes: true } get api("/#{attributable_name}", admin), params: { with_custom_attributes: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.size).to be 2 expect(json_response.size).to be 2
attributable_response = json_response.find { |r| r['id'] == attributable.id } attributable_response = json_response.find { |r| r['id'] == attributable.id }
...@@ -79,7 +79,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -79,7 +79,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'does not include custom attributes' do it 'does not include custom attributes' do
get api("/#{attributable_name}/#{attributable.id}", user), params: { with_custom_attributes: true } get api("/#{attributable_name}/#{attributable.id}", user), params: { with_custom_attributes: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to include 'custom_attributes' expect(json_response).not_to include 'custom_attributes'
end end
end end
...@@ -88,14 +88,14 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -88,14 +88,14 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'does not include custom attributes by default' do it 'does not include custom attributes by default' do
get api("/#{attributable_name}/#{attributable.id}", admin) get api("/#{attributable_name}/#{attributable.id}", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).not_to include 'custom_attributes' expect(json_response).not_to include 'custom_attributes'
end end
it 'includes custom attributes if requested' do it 'includes custom attributes if requested' do
get api("/#{attributable_name}/#{attributable.id}", admin), params: { with_custom_attributes: true } get api("/#{attributable_name}/#{attributable.id}", admin), params: { with_custom_attributes: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['custom_attributes']).to contain_exactly( expect(json_response['custom_attributes']).to contain_exactly(
{ 'key' => 'foo', 'value' => 'foo' }, { 'key' => 'foo', 'value' => 'foo' },
{ 'key' => 'bar', 'value' => 'bar' } { 'key' => 'bar', 'value' => 'bar' }
...@@ -115,7 +115,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -115,7 +115,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it 'returns all custom attributes' do it 'returns all custom attributes' do
get api("/#{attributable_name}/#{attributable.id}/custom_attributes", admin) get api("/#{attributable_name}/#{attributable.id}/custom_attributes", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to contain_exactly( expect(json_response).to contain_exactly(
{ 'key' => 'foo', 'value' => 'foo' }, { 'key' => 'foo', 'value' => 'foo' },
{ 'key' => 'bar', 'value' => 'bar' } { 'key' => 'bar', 'value' => 'bar' }
...@@ -135,7 +135,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -135,7 +135,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
it'returns a single custom attribute' do it'returns a single custom attribute' do
get api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin) get api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq({ 'key' => 'foo', 'value' => 'foo' }) expect(json_response).to eq({ 'key' => 'foo', 'value' => 'foo' })
end end
end end
...@@ -154,7 +154,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -154,7 +154,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
put api("/#{attributable_name}/#{attributable.id}/custom_attributes/new", admin), params: { value: 'new' } put api("/#{attributable_name}/#{attributable.id}/custom_attributes/new", admin), params: { value: 'new' }
end.to change { attributable.custom_attributes.count }.by(1) end.to change { attributable.custom_attributes.count }.by(1)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq({ 'key' => 'new', 'value' => 'new' }) expect(json_response).to eq({ 'key' => 'new', 'value' => 'new' })
expect(attributable.custom_attributes.find_by(key: 'new').value).to eq 'new' expect(attributable.custom_attributes.find_by(key: 'new').value).to eq 'new'
end end
...@@ -164,7 +164,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -164,7 +164,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
put api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin), params: { value: 'new' } put api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin), params: { value: 'new' }
end.not_to change { attributable.custom_attributes.count } end.not_to change { attributable.custom_attributes.count }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response).to eq({ 'key' => 'foo', 'value' => 'new' }) expect(json_response).to eq({ 'key' => 'foo', 'value' => 'new' })
expect(custom_attribute1.reload.value).to eq 'new' expect(custom_attribute1.reload.value).to eq 'new'
end end
...@@ -184,7 +184,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| ...@@ -184,7 +184,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name|
delete api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin) delete api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin)
end.to change { attributable.custom_attributes.count }.by(-1) end.to change { attributable.custom_attributes.count }.by(-1)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
expect(attributable.custom_attributes.find_by(key: 'foo')).to be_nil expect(attributable.custom_attributes.find_by(key: 'foo')).to be_nil
end end
end end
......
...@@ -7,7 +7,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -7,7 +7,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
discussion = json_response.find { |record| record['id'] == diff_note.discussion_id } discussion = json_response.find { |record| record['id'] == diff_note.discussion_id }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(discussion).not_to be_nil expect(discussion).not_to be_nil
expect(discussion['individual_note']).to eq(false) expect(discussion['individual_note']).to eq(false)
expect(discussion['notes'].first['body']).to eq(diff_note.note) expect(discussion['notes'].first['body']).to eq(diff_note.note)
...@@ -18,7 +18,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -18,7 +18,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
it "returns a discussion by id" do it "returns a discussion by id" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/#{diff_note.discussion_id}", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/#{diff_note.discussion_id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq(diff_note.discussion_id) expect(json_response['id']).to eq(diff_note.discussion_id)
expect(json_response['notes'].first['body']).to eq(diff_note.note) expect(json_response['notes'].first['body']).to eq(diff_note.note)
expect(json_response['notes'].first['position']).to eq(diff_note.position.to_h.stringify_keys) expect(json_response['notes'].first['position']).to eq(diff_note.position.to_h.stringify_keys)
...@@ -32,7 +32,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -32,7 +32,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user),
params: { body: 'hi!', position: position } params: { body: 'hi!', position: position }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['notes'].first['body']).to eq('hi!') expect(json_response['notes'].first['body']).to eq('hi!')
expect(json_response['notes'].first['type']).to eq('DiffNote') expect(json_response['notes'].first['type']).to eq('DiffNote')
expect(json_response['notes'].first['position']).to eq(position.stringify_keys) expect(json_response['notes'].first['position']).to eq(position.stringify_keys)
...@@ -45,7 +45,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -45,7 +45,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user),
params: { body: 'hi!', position: position } params: { body: 'hi!', position: position }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a 400 bad request error when the position is not valid for this discussion" do it "returns a 400 bad request error when the position is not valid for this discussion" do
...@@ -54,7 +54,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -54,7 +54,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user),
params: { body: 'hi!', position: position } params: { body: 'hi!', position: position }
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
end end
...@@ -64,7 +64,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name| ...@@ -64,7 +64,7 @@ shared_examples 'diff discussions API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{diff_note.discussion_id}/notes", user), params: { body: 'hi!' } "discussions/#{diff_note.discussion_id}/notes", user), params: { body: 'hi!' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['type']).to eq('DiffNote') expect(json_response['type']).to eq('DiffNote')
end end
......
...@@ -23,7 +23,7 @@ shared_examples 'with cross-reference system notes' do ...@@ -23,7 +23,7 @@ shared_examples 'with cross-reference system notes' do
it 'returns only the note that the user should see' do it 'returns only the note that the user should see' do
get api(url, user, personal_access_token: pat) get api(url, user, personal_access_token: pat)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(notes_in_response.count).to eq(1) expect(notes_in_response.count).to eq(1)
...@@ -40,7 +40,7 @@ shared_examples 'with cross-reference system notes' do ...@@ -40,7 +40,7 @@ shared_examples 'with cross-reference system notes' do
get api(url, user, personal_access_token: pat) get api(url, user, personal_access_token: pat)
end end
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
RequestStore.clear! RequestStore.clear!
...@@ -50,7 +50,7 @@ shared_examples 'with cross-reference system notes' do ...@@ -50,7 +50,7 @@ shared_examples 'with cross-reference system notes' do
RequestStore.clear! RequestStore.clear!
expect { get api(url, user, personal_access_token: pat) }.not_to exceed_query_limit(control) expect { get api(url, user, personal_access_token: pat) }.not_to exceed_query_limit(control)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
end end
end end
...@@ -59,7 +59,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -59,7 +59,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "returns an array of discussions" do it "returns an array of discussions" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", 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['id']).to eq(note.discussion_id) expect(json_response.first['id']).to eq(note.discussion_id)
...@@ -68,7 +68,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -68,7 +68,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "returns a 404 error when noteable id not found" do it "returns a 404 error when noteable id not found" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/12345/discussions", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/12345/discussions", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it "returns 404 when not authorized" do it "returns 404 when not authorized" do
...@@ -76,7 +76,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -76,7 +76,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", private_user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", private_user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -84,7 +84,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -84,7 +84,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "returns a discussion by id" do it "returns a discussion by id" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/#{note.discussion_id}", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/#{note.discussion_id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq(note.discussion_id) expect(json_response['id']).to eq(note.discussion_id)
expect(json_response['notes'].first['body']).to eq(note.note) expect(json_response['notes'].first['body']).to eq(note.note)
end end
...@@ -92,7 +92,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -92,7 +92,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "returns a 404 error if discussion not found" do it "returns a 404 error if discussion not found" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/12345", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions/12345", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -100,7 +100,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -100,7 +100,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "creates a new note" do it "creates a new note" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), params: { body: 'hi!' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), params: { body: 'hi!' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['notes'].first['body']).to eq('hi!') expect(json_response['notes'].first['body']).to eq('hi!')
expect(json_response['notes'].first['author']['username']).to eq(user.username) expect(json_response['notes'].first['author']['username']).to eq(user.username)
end end
...@@ -108,13 +108,13 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -108,13 +108,13 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
it "returns a 400 bad request error if body not given" do it "returns a 400 bad request error if body not given" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user) post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a 401 unauthorized error if user not authenticated" do it "returns a 401 unauthorized error if user not authenticated" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions"), params: { body: 'hi!' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions"), params: { body: 'hi!' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it 'tracks a Notes::CreateService event' do it 'tracks a Notes::CreateService event' do
...@@ -146,7 +146,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -146,7 +146,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user),
params: { body: 'hi!', created_at: creation_time } params: { body: 'hi!', created_at: creation_time }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['notes'].first['body']).to eq('hi!') expect(json_response['notes'].first['body']).to eq('hi!')
expect(json_response['notes'].first['author']['username']).to eq(user.username) expect(json_response['notes'].first['author']['username']).to eq(user.username)
expect(Time.parse(json_response['notes'].first['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['notes'].first['created_at'])).to be_like_time(creation_time)
...@@ -162,7 +162,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -162,7 +162,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", private_user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", private_user),
params: { body: 'Foo' } params: { body: 'Foo' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -181,7 +181,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -181,7 +181,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
end end
it 'raises 404 error' do it 'raises 404 error' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -191,7 +191,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -191,7 +191,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
end end
it 'raises 404 error' do it 'raises 404 error' do
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -203,7 +203,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -203,7 +203,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes", user), params: { body: 'Hello!' } "discussions/#{note.discussion_id}/notes", user), params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
expect(json_response['type']).to eq('DiscussionNote') expect(json_response['type']).to eq('DiscussionNote')
end end
...@@ -212,7 +212,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -212,7 +212,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes", user) "discussions/#{note.discussion_id}/notes", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
context 'when the discussion is an individual note' do context 'when the discussion is an individual note' do
...@@ -225,13 +225,13 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -225,13 +225,13 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
if can_reply_to_individual_notes if can_reply_to_individual_notes
it 'creates a new discussion' do it 'creates a new discussion' do
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['type']).to eq('DiscussionNote') expect(json_response['type']).to eq('DiscussionNote')
end end
else else
it 'returns 400 bad request' do it 'returns 400 bad request' do
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
end end
...@@ -242,7 +242,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -242,7 +242,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user), params: { body: 'Hello!' } "discussions/#{note.discussion_id}/notes/#{note.id}", user), params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
...@@ -251,14 +251,14 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -251,14 +251,14 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
"discussions/#{note.discussion_id}/notes/12345", user), "discussions/#{note.discussion_id}/notes/12345", user),
params: { body: 'Hello!' } params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 400 bad request error if body not given' do it 'returns a 400 bad request error if body not given' do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user) "discussions/#{note.discussion_id}/notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -267,18 +267,18 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r ...@@ -267,18 +267,18 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user) "discussions/#{note.discussion_id}/notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
# Check if note is really deleted # Check if note is really deleted
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user) "discussions/#{note.discussion_id}/notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/12345", user) "discussions/#{note.discussion_id}/notes/12345", 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
......
...@@ -6,7 +6,7 @@ shared_examples 'issuable participants endpoint' do ...@@ -6,7 +6,7 @@ shared_examples 'issuable participants endpoint' do
it 'returns participants' do it 'returns participants' do
get api("/projects/#{project.id}/#{area}/#{entity.iid}/participants", user) get api("/projects/#{project.id}/#{area}/#{entity.iid}/participants", 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.size).to eq(entity.participants.size) expect(json_response.size).to eq(entity.participants.size)
...@@ -20,12 +20,12 @@ shared_examples 'issuable participants endpoint' do ...@@ -20,12 +20,12 @@ shared_examples 'issuable participants endpoint' do
it 'returns a 404 when iid does not exist' do it 'returns a 404 when iid does not exist' do
get api("/projects/#{project.id}/#{area}/999/participants", user) get api("/projects/#{project.id}/#{area}/999/participants", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 404 when id is used instead of iid' do it 'returns a 404 when id is used instead of iid' do
get api("/projects/#{project.id}/#{area}/#{entity.id}/participants", user) get api("/projects/#{project.id}/#{area}/#{entity.id}/participants", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -82,7 +82,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -82,7 +82,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it "returns an array of notes" do it "returns an array of notes" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", 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['body']).to eq(note.note) expect(json_response.first['body']).to eq(note.note)
...@@ -91,7 +91,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -91,7 +91,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it "returns a 404 error when noteable id not found" do it "returns a 404 error when noteable id not found" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/12345/notes", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/12345/notes", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it "returns 404 when not authorized" do it "returns 404 when not authorized" do
...@@ -99,7 +99,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -99,7 +99,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -107,14 +107,14 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -107,14 +107,14 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it "returns a note by id" do it "returns a note by id" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/#{note.id}", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['body']).to eq(note.note) expect(json_response['body']).to eq(note.note)
end end
it "returns a 404 error if note not found" do it "returns a 404 error if note not found" do
get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", user) get api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -122,7 +122,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -122,7 +122,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it "creates a new note" do it "creates a new note" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: { body: 'hi!' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: { body: 'hi!' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
end end
...@@ -130,13 +130,13 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -130,13 +130,13 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it "returns a 400 bad request error if body not given" do it "returns a 400 bad request error if body not given" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user) post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a 401 unauthorized error if user not authenticated" do it "returns a 401 unauthorized error if user not authenticated" do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes"), params: { body: 'hi!' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes"), params: { body: 'hi!' }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "creates an activity event when a note is created", :sidekiq_might_not_need_inline do it "creates an activity event when a note is created", :sidekiq_might_not_need_inline do
...@@ -154,7 +154,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -154,7 +154,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
admin = create(:admin) admin = create(:admin)
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", admin), params: params post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", admin), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(admin.username) expect(json_response['author']['username']).to eq(admin.username)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
...@@ -167,7 +167,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -167,7 +167,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it 'sets the creation time on the new note' do it 'sets the creation time on the new note' do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
...@@ -185,7 +185,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -185,7 +185,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user2), params: params post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user2), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user2.username) expect(json_response['author']['username']).to eq(user2.username)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
...@@ -197,7 +197,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -197,7 +197,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it 'sets the creation time on the new note' do it 'sets the creation time on the new note' do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user.username) expect(json_response['author']['username']).to eq(user.username)
expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).to be_like_time(creation_time)
...@@ -212,7 +212,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -212,7 +212,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
parent.add_developer(user2) parent.add_developer(user2)
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user2), params: params post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user2), params: params
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq('hi!') expect(json_response['body']).to eq('hi!')
expect(json_response['author']['username']).to eq(user2.username) expect(json_response['author']['username']).to eq(user2.username)
expect(Time.parse(json_response['created_at'])).not_to be_like_time(creation_time) expect(Time.parse(json_response['created_at'])).not_to be_like_time(creation_time)
...@@ -226,7 +226,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -226,7 +226,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
parent.add_developer(private_user) parent.add_developer(private_user)
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user), params: { body: ':+1:' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user), params: { body: ':+1:' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq(':+1:') expect(json_response['body']).to eq(':+1:')
end end
end end
...@@ -235,7 +235,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -235,7 +235,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
it 'creates a new note' do it 'creates a new note' do
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: { body: ':+1:' } post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", user), params: { body: ':+1:' }
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(:created)
expect(json_response['body']).to eq(':+1:') expect(json_response['body']).to eq(':+1:')
end end
end end
...@@ -249,7 +249,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -249,7 +249,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user), post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes", private_user),
params: { body: 'Foo' } params: { body: 'Foo' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -259,7 +259,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -259,7 +259,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"notes/#{note.id}", user), params: { body: 'Hello!' } "notes/#{note.id}", user), params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['body']).to eq('Hello!') expect(json_response['body']).to eq('Hello!')
end end
...@@ -267,14 +267,14 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -267,14 +267,14 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", user), put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", user),
params: { body: 'Hello!' } params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 400 bad request error if body not given' do it 'returns a 400 bad request error if body not given' do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"notes/#{note.id}", user) "notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
end end
...@@ -283,17 +283,17 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| ...@@ -283,17 +283,17 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name|
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"notes/#{note.id}", user) "notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(204) expect(response).to have_gitlab_http_status(:no_content)
# Check if note is really deleted # Check if note is really deleted
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"notes/#{note.id}", user) "notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 404 error when note id not found' do it 'returns a 404 error when note id not found' do
delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", user) delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/notes/12345", 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
......
...@@ -6,7 +6,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -6,7 +6,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", user), params: { resolved: true } "discussions/#{note.discussion_id}", user), params: { resolved: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['notes'].size).to eq(1) expect(json_response['notes'].size).to eq(1)
expect(json_response['notes'][0]['resolved']).to eq(true) expect(json_response['notes'][0]['resolved']).to eq(true)
end end
...@@ -15,7 +15,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -15,7 +15,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", user), params: { resolved: false } "discussions/#{note.discussion_id}", user), params: { resolved: false }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['notes'].size).to eq(1) expect(json_response['notes'].size).to eq(1)
expect(json_response['notes'][0]['resolved']).to eq(false) expect(json_response['notes'][0]['resolved']).to eq(false)
end end
...@@ -24,21 +24,21 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -24,21 +24,21 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", user) "discussions/#{note.discussion_id}", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a 401 unauthorized error if user is not authenticated" do it "returns a 401 unauthorized error if user is not authenticated" do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}"), params: { resolved: true } "discussions/#{note.discussion_id}"), params: { resolved: true }
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(:unauthorized)
end end
it "returns a 403 error if user resolves discussion of someone else" do it "returns a 403 error if user resolves discussion of someone else" do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", private_user), params: { resolved: true } "discussions/#{note.discussion_id}", private_user), params: { resolved: true }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
context 'when user does not have access to read the discussion' do context 'when user does not have access to read the discussion' do
...@@ -50,7 +50,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -50,7 +50,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}", private_user), params: { resolved: true } "discussions/#{note.discussion_id}", private_user), params: { resolved: true }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
...@@ -60,7 +60,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -60,7 +60,7 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user), params: { resolved: true } "discussions/#{note.discussion_id}/notes/#{note.id}", user), params: { resolved: true }
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['resolved']).to eq(true) expect(json_response['resolved']).to eq(true)
end end
...@@ -69,21 +69,21 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ ...@@ -69,21 +69,21 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_
"discussions/#{note.discussion_id}/notes/12345", user), "discussions/#{note.discussion_id}/notes/12345", user),
params: { body: 'Hello!' } params: { body: 'Hello!' }
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns a 400 bad request error if neither body nor resolved parameter is given' do it 'returns a 400 bad request error if neither body nor resolved parameter is given' do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", user) "discussions/#{note.discussion_id}/notes/#{note.id}", user)
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
end end
it "returns a 403 error if user resolves note of someone else" do it "returns a 403 error if user resolves note of someone else" do
put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\
"discussions/#{note.discussion_id}/notes/#{note.id}", private_user), params: { resolved: true } "discussions/#{note.discussion_id}/notes/#{note.id}", private_user), params: { resolved: true }
expect(response).to have_gitlab_http_status(403) expect(response).to have_gitlab_http_status(:forbidden)
end end
end end
end end
...@@ -13,7 +13,7 @@ shared_examples_for '400 response' do ...@@ -13,7 +13,7 @@ shared_examples_for '400 response' do
end end
it 'returns 400' do it 'returns 400' do
expect(response).to have_gitlab_http_status(400) expect(response).to have_gitlab_http_status(:bad_request)
if message.present? if message.present?
expect(json_response['message']).to eq(message) expect(json_response['message']).to eq(message)
...@@ -28,7 +28,7 @@ shared_examples_for '403 response' do ...@@ -28,7 +28,7 @@ shared_examples_for '403 response' 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)
end end
end end
...@@ -41,7 +41,7 @@ shared_examples_for '404 response' do ...@@ -41,7 +41,7 @@ shared_examples_for '404 response' do
end end
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).to be_an Object expect(json_response).to be_an Object
if message.present? if message.present?
...@@ -60,7 +60,7 @@ shared_examples_for '412 response' do ...@@ -60,7 +60,7 @@ shared_examples_for '412 response' do
end end
it 'returns 412 with a JSON error' do it 'returns 412 with a JSON error' do
expect(response).to have_gitlab_http_status(412) expect(response).to have_gitlab_http_status(:precondition_failed)
expect(json_response).to eq('message' => '412 Precondition Failed') expect(json_response).to eq('message' => '412 Precondition Failed')
end end
end end
......
...@@ -33,7 +33,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -33,7 +33,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
# At first, allow requests under the rate limit. # At first, allow requests under the rate limit.
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
# the last straw # the last straw
...@@ -43,7 +43,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -43,7 +43,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
it 'allows requests after throttling and then waiting for the next period' do it 'allows requests after throttling and then waiting for the next period' do
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_rejection { make_request(request_args) } expect_rejection { make_request(request_args) }
...@@ -51,7 +51,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -51,7 +51,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
Timecop.travel(period.from_now) do Timecop.travel(period.from_now) do
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_rejection { make_request(request_args) } expect_rejection { make_request(request_args) }
...@@ -61,18 +61,18 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -61,18 +61,18 @@ shared_examples_for 'rate-limited token-authenticated requests' do
it 'counts requests from different users separately, even from the same IP' do it 'counts requests from different users separately, even from the same IP' do
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
# would be over the limit if this wasn't a different user # would be over the limit if this wasn't a different user
make_request(other_user_request_args) make_request(other_user_request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
it 'counts all requests from the same user, even via different IPs' do it 'counts all requests from the same user, even via different IPs' do
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4') expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
...@@ -83,7 +83,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -83,7 +83,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
it 'logs RackAttack info into structured logs' do it 'logs RackAttack info into structured logs' do
requests_per_period.times do requests_per_period.times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
arguments = { arguments = {
...@@ -112,7 +112,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do ...@@ -112,7 +112,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do
it 'allows requests over the rate limit' do it 'allows requests over the rate limit' do
(1 + requests_per_period).times do (1 + requests_per_period).times do
make_request(request_args) make_request(request_args)
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
end end
end end
...@@ -160,7 +160,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -160,7 +160,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
# At first, allow requests under the rate limit. # At first, allow requests under the rate limit.
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
# the last straw # the last straw
...@@ -170,7 +170,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -170,7 +170,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
it 'allows requests after throttling and then waiting for the next period' do it 'allows requests after throttling and then waiting for the next period' do
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_rejection { request_authenticated_web_url } expect_rejection { request_authenticated_web_url }
...@@ -178,7 +178,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -178,7 +178,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
Timecop.travel(period.from_now) do Timecop.travel(period.from_now) do
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_rejection { request_authenticated_web_url } expect_rejection { request_authenticated_web_url }
...@@ -188,20 +188,20 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -188,20 +188,20 @@ shared_examples_for 'rate-limited web authenticated requests' do
it 'counts requests from different users separately, even from the same IP' do it 'counts requests from different users separately, even from the same IP' do
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
# would be over the limit if this wasn't a different user # would be over the limit if this wasn't a different user
login_as(create(:user)) login_as(create(:user))
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
it 'counts all requests from the same user, even via different IPs' do it 'counts all requests from the same user, even via different IPs' do
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4') expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
...@@ -212,7 +212,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -212,7 +212,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
it 'logs RackAttack info into structured logs' do it 'logs RackAttack info into structured logs' do
requests_per_period.times do requests_per_period.times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
arguments = { arguments = {
...@@ -241,7 +241,7 @@ shared_examples_for 'rate-limited web authenticated requests' do ...@@ -241,7 +241,7 @@ shared_examples_for 'rate-limited web authenticated requests' do
it 'allows requests over the rate limit' do it 'allows requests over the rate limit' do
(1 + requests_per_period).times do (1 + requests_per_period).times do
request_authenticated_web_url request_authenticated_web_url
expect(response).not_to have_http_status 429 expect(response).not_to have_gitlab_http_status(:too_many_requests)
end end
end end
end end
......
...@@ -8,7 +8,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -8,7 +8,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
it "returns an array of resource label events" do it "returns an array of resource label events" do
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events", user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events", 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['id']).to eq(event.id) expect(json_response.first['id']).to eq(event.id)
...@@ -17,7 +17,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -17,7 +17,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
it "returns a 404 error when eventable id not found" do it "returns a 404 error when eventable id not found" do
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/12345/resource_label_events", user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/12345/resource_label_events", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it "returns 404 when not authorized" do it "returns 404 when not authorized" do
...@@ -26,7 +26,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -26,7 +26,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events", private_user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events", private_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 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -60,7 +60,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
it "returns a resource label event by id" do it "returns a resource label event by id" do
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", user)
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['id']).to eq(event.id) expect(json_response['id']).to eq(event.id)
end end
...@@ -70,13 +70,13 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -70,13 +70,13 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", private_user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", private_user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
it "returns a 404 error if resource label event not found" do it "returns a 404 error if resource label event not found" do
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/12345", user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/12345", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
...@@ -88,7 +88,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_ ...@@ -88,7 +88,7 @@ shared_examples 'resource_label_events API' do |parent_type, eventable_type, id_
it "returns a 404 error if cross-reference project is not accessible" do it "returns a 404 error if cross-reference project is not accessible" do
get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", user) get api("/#{parent_type}/#{parent.id}/#{eventable_type}/#{eventable[id_name]}/resource_label_events/#{event.id}", user)
expect(response).to have_gitlab_http_status(404) expect(response).to have_gitlab_http_status(:not_found)
end end
end end
end end
......
...@@ -69,7 +69,7 @@ shared_examples 'user login request with unique ip limit' do |success_status = 2 ...@@ -69,7 +69,7 @@ shared_examples 'user login request with unique ip limit' do |success_status = 2
it 'blocks user authenticating from two distinct ips' do it 'blocks user authenticating from two distinct ips' do
expect(request_from_ip('ip')).to have_gitlab_http_status(success_status) expect(request_from_ip('ip')).to have_gitlab_http_status(success_status)
expect(request_from_ip('ip2')).to have_gitlab_http_status(403) expect(request_from_ip('ip2')).to have_gitlab_http_status(:forbidden)
end end
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