diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 09:08:32 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 09:08:32 +0000 |
commit | 2ee5991b42717969af93cb30d863aafab04dff8a (patch) | |
tree | c09c0b7b4d02ceb9d6ac090c1ccfb93effb8a368 /spec | |
parent | 6b1ba27ef7373815ea29dc5b80eab846c8acd022 (diff) | |
download | gitlab-ce-2ee5991b42717969af93cb30d863aafab04dff8a.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
19 files changed, 199 insertions, 143 deletions
diff --git a/spec/frontend/monitoring/components/dashboard_spec.js b/spec/frontend/monitoring/components/dashboard_spec.js index 85408d57dde..c5cb67b4e6f 100644 --- a/spec/frontend/monitoring/components/dashboard_spec.js +++ b/spec/frontend/monitoring/components/dashboard_spec.js @@ -124,9 +124,6 @@ describe('Dashboard', () => { .then(() => { expect(wrapper.vm.showEmptyState).toEqual(false); expect(wrapper.vm.$el.querySelector('.prometheus-panel')).toEqual(null); - // TODO: The last expectation doesn't belong here, it belongs in a `group_group_spec.js` file - // Issue: https://gitlab.com/gitlab-org/gitlab/issues/118780 - // expect(wrapper.vm.$el.querySelector('.prometheus-graph-group')).toBeTruthy(); done(); }) diff --git a/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js b/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js index 97fcdc67791..6ae405017c9 100644 --- a/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js +++ b/spec/frontend/vue_shared/components/markdown/suggestion_diff_row_spec.js @@ -63,21 +63,59 @@ describe('SuggestionDiffRow', () => { it('renders the plain text when it is available but rich text is not', () => { factory({ propsData: { - line: Object.assign({}, newLine, { rich_text: undefined }), + line: { + ...newLine, + rich_text: undefined, + }, }, }); expect(wrapper.find('td.line_content').text()).toEqual('newplaintext'); }); - it('renders a zero-width space when it has no plain or rich texts', () => { + it('switches to table-cell display when it has no plain or rich texts', () => { factory({ propsData: { - line: Object.assign({}, newLine, { rich_text: undefined, text: undefined }), + line: { + ...newLine, + text: undefined, + rich_text: undefined, + }, }, }); - expect(wrapper.find('td.line_content').text()).toEqual('\u200B'); + const lineContent = wrapper.find('td.line_content'); + + expect(lineContent.classes()).toContain('d-table-cell'); + expect(lineContent.text()).toEqual(''); + }); + + it('does not switch to table-cell display if it has either plain or rich texts', () => { + let lineContent; + + factory({ + propsData: { + line: { + ...newLine, + text: undefined, + }, + }, + }); + + lineContent = wrapper.find('td.line_content'); + expect(lineContent.classes()).not.toContain('d-table-cell'); + + factory({ + propsData: { + line: { + ...newLine, + rich_text: undefined, + }, + }, + }); + + lineContent = wrapper.find('td.line_content'); + expect(lineContent.classes()).not.toContain('d-table-cell'); }); }); diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 0a22a09b8a6..5af56aa6f75 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -913,6 +913,27 @@ describe API::Users do end end + describe 'GET /user/:user_id/keys' do + it 'returns 404 for non-existing user' do + get api("/users/#{not_existing_user_id}/keys") + + expect(response).to have_gitlab_http_status(404) + expect(json_response['message']).to eq('404 User Not Found') + end + + it 'returns array of ssh keys' do + user.keys << key + user.save + + get api("/users/#{user.username}/keys") + + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response.first['title']).to eq(key.title) + end + end + describe 'DELETE /user/:id/keys/:key_id' do before do admin diff --git a/spec/support/shared_examples/controllers/external_authorization_service_shared_examples.rb b/spec/support/shared_examples/controllers/external_authorization_service_shared_examples.rb index d8a1ae83f61..cccce7b91b5 100644 --- a/spec/support/shared_examples/controllers/external_authorization_service_shared_examples.rb +++ b/spec/support/shared_examples/controllers/external_authorization_service_shared_examples.rb @@ -16,7 +16,7 @@ shared_examples 'disabled when using an external authorization service' do subject - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end @@ -37,6 +37,6 @@ shared_examples 'unauthorized when external service denies access' do subject - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end diff --git a/spec/support/shared_examples/controllers/paginated_collection_shared_examples.rb b/spec/support/shared_examples/controllers/paginated_collection_shared_examples.rb index bd84bd1093f..41a8d2d8117 100644 --- a/spec/support/shared_examples/controllers/paginated_collection_shared_examples.rb +++ b/spec/support/shared_examples/controllers/paginated_collection_shared_examples.rb @@ -11,7 +11,7 @@ shared_examples 'paginated collection' do it 'renders a page number that is not ouf of range' do 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 it 'redirects to last_page if page number is larger than number of pages' do diff --git a/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb b/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb index 5dea17069f9..8e5fae5da18 100644 --- a/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb +++ b/spec/support/shared_examples/controllers/repository_lfs_file_load_examples.rb @@ -51,7 +51,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| subject - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end context 'and lfs uses object storage' do @@ -65,7 +65,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| it 'responds with redirect to file' do 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) end @@ -84,7 +84,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| it 'does not serve the file' do subject - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -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 subject - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end 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 = {}| subject - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end 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 = {}| subject - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -154,7 +154,7 @@ shared_examples 'a controller that can serve LFS files' do |options = {}| 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-Disposition']) .to eq('inline') diff --git a/spec/support/shared_examples/controllers/todos_shared_examples.rb b/spec/support/shared_examples/controllers/todos_shared_examples.rb index 914bf506320..e220f6bfc9b 100644 --- a/spec/support/shared_examples/controllers/todos_shared_examples.rb +++ b/spec/support/shared_examples/controllers/todos_shared_examples.rb @@ -12,13 +12,13 @@ shared_examples 'todos actions' do post_create 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 it 'returns todo path and pending count' do 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['delete_path']).to match(%r{/dashboard/todos/\d{1}}) end @@ -31,7 +31,7 @@ shared_examples 'todos actions' do post_create 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 it 'does not create todo when user is not logged in' do @@ -39,7 +39,7 @@ shared_examples 'todos actions' do post_create 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 diff --git a/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb b/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb index 8962d98218a..11dd8042b45 100644 --- a/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb +++ b/spec/support/shared_examples/controllers/uploads_actions_shared_examples.rb @@ -27,7 +27,7 @@ shared_examples 'handle uploads' do it "returns an error" do 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 @@ -84,7 +84,7 @@ shared_examples 'handle uploads' do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -110,7 +110,7 @@ shared_examples 'handle uploads' do it "responds with status 200" do show_upload - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -123,7 +123,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -135,7 +135,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -149,7 +149,7 @@ shared_examples 'handle uploads' do it "responds with status 200" do show_upload - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -161,7 +161,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -182,7 +182,7 @@ shared_examples 'handle uploads' do it "responds with status 200" do show_upload - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -226,7 +226,7 @@ shared_examples 'handle uploads' do it "responds with status 200" do show_upload - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -238,7 +238,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -253,7 +253,7 @@ shared_examples 'handle uploads' do it "responds with status 200" do show_upload - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end end @@ -265,7 +265,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -278,7 +278,7 @@ shared_examples 'handle uploads' do it "responds with status 404" do show_upload - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -321,7 +321,7 @@ shared_examples 'handle uploads authorize' do end it 'responds with status 200' do - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) end it 'uses the gitlab-workhorse content type' do diff --git a/spec/support/shared_examples/discussions_provider_shared_examples.rb b/spec/support/shared_examples/discussions_provider_shared_examples.rb index 77cf1ac3f51..0e7f491c6a4 100644 --- a/spec/support/shared_examples/discussions_provider_shared_examples.rb +++ b/spec/support/shared_examples/discussions_provider_shared_examples.rb @@ -6,7 +6,7 @@ shared_examples 'discussions provider' do it 'returns the expected discussions' do 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(json_response.size).to eq(expected_discussion_count) diff --git a/spec/support/shared_examples/requests/api/custom_attributes_shared_examples.rb b/spec/support/shared_examples/requests/api/custom_attributes_shared_examples.rb index 776a0bdd29e..22bd6e9cdf7 100644 --- a/spec/support/shared_examples/requests/api/custom_attributes_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/custom_attributes_shared_examples.rb @@ -13,7 +13,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'does not filter by custom attributes' do 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.map { |r| r['id'] }).to contain_exactly attributable.id, other_attributable.id end @@ -23,7 +23,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'filters by custom attributes' do 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.first['id']).to eq attributable.id end @@ -39,7 +39,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'does not include custom attributes' do 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.first).not_to include 'custom_attributes' end @@ -49,7 +49,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'does not include custom attributes by default' do 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.first).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| it 'includes custom attributes if requested' do 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 attributable_response = json_response.find { |r| r['id'] == attributable.id } @@ -79,7 +79,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'does not include custom attributes' do 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' end end @@ -88,14 +88,14 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'does not include custom attributes by default' do 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' end it 'includes custom attributes if requested' do 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( { 'key' => 'foo', 'value' => 'foo' }, { 'key' => 'bar', 'value' => 'bar' } @@ -115,7 +115,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it 'returns all custom attributes' do 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( { 'key' => 'foo', 'value' => 'foo' }, { 'key' => 'bar', 'value' => 'bar' } @@ -135,7 +135,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| it'returns a single custom attribute' do 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' }) end end @@ -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' } 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(attributable.custom_attributes.find_by(key: 'new').value).to eq 'new' end @@ -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' } 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(custom_attribute1.reload.value).to eq 'new' end @@ -184,7 +184,7 @@ shared_examples 'custom attributes endpoints' do |attributable_name| delete api("/#{attributable_name}/#{attributable.id}/custom_attributes/foo", admin) 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 end end diff --git a/spec/support/shared_examples/requests/api/diff_discussions.rb b/spec/support/shared_examples/requests/api/diff_discussions.rb index a7774d17d3c..8ef3ed3f057 100644 --- a/spec/support/shared_examples/requests/api/diff_discussions.rb +++ b/spec/support/shared_examples/requests/api/diff_discussions.rb @@ -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 } - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) expect(discussion).not_to be_nil expect(discussion['individual_note']).to eq(false) 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| it "returns a discussion by id" do 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['notes'].first['body']).to eq(diff_note.note) 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| post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), 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['type']).to eq('DiffNote') 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| post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), params: { body: 'hi!', position: position } - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(:bad_request) end 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| post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", user), 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 @@ -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]}/"\ "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['type']).to eq('DiffNote') end diff --git a/spec/support/shared_examples/requests/api/discussions.rb b/spec/support/shared_examples/requests/api/discussions.rb index 2a5a48f3054..232c8d20025 100644 --- a/spec/support/shared_examples/requests/api/discussions.rb +++ b/spec/support/shared_examples/requests/api/discussions.rb @@ -23,7 +23,7 @@ shared_examples 'with cross-reference system notes' do it 'returns only the note that the user should see' do 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(notes_in_response.count).to eq(1) @@ -40,7 +40,7 @@ shared_examples 'with cross-reference system notes' do get api(url, user, personal_access_token: pat) end - expect(response).to have_gitlab_http_status(200) + expect(response).to have_gitlab_http_status(:ok) RequestStore.clear! @@ -50,7 +50,7 @@ shared_examples 'with cross-reference system notes' do RequestStore.clear! 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 @@ -59,7 +59,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r it "returns an array of discussions" do 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(json_response).to be_an Array 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 it "returns a 404 error when noteable id not found" do 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 it "returns 404 when not authorized" do @@ -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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -84,7 +84,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r it "returns a discussion by id" do 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['notes'].first['body']).to eq(note.note) end @@ -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 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 @@ -100,7 +100,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r it "creates a new note" do 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['author']['username']).to eq(user.username) end @@ -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 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 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!' } - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) end it 'tracks a Notes::CreateService event' do @@ -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), 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['author']['username']).to eq(user.username) 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 post api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/discussions", private_user), params: { body: 'Foo' } - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -181,7 +181,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r end it 'raises 404 error' do - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -191,7 +191,7 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r end 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 @@ -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]}/"\ "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['type']).to eq('DiscussionNote') end @@ -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]}/"\ "discussions/#{note.discussion_id}/notes", user) - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(:bad_request) end 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 if can_reply_to_individual_notes 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['type']).to eq('DiscussionNote') end else 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 @@ -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]}/"\ "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!') end @@ -251,14 +251,14 @@ shared_examples 'discussions API' do |parent_type, noteable_type, id_name, can_r "discussions/#{note.discussion_id}/notes/12345", user), params: { body: 'Hello!' } - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end it 'returns a 400 bad request error if body not given' do put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 @@ -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]}/"\ "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 delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 it 'returns a 404 error when note id not found' do delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 it_behaves_like '412 response' do diff --git a/spec/support/shared_examples/requests/api/issuable_participants_examples.rb b/spec/support/shared_examples/requests/api/issuable_participants_examples.rb index 9fe6288d53f..013b135235c 100644 --- a/spec/support/shared_examples/requests/api/issuable_participants_examples.rb +++ b/spec/support/shared_examples/requests/api/issuable_participants_examples.rb @@ -6,7 +6,7 @@ shared_examples 'issuable participants endpoint' do it 'returns participants' do 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(json_response).to be_an Array expect(json_response.size).to eq(entity.participants.size) @@ -20,12 +20,12 @@ shared_examples 'issuable participants endpoint' do it 'returns a 404 when iid does not exist' do 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 it 'returns a 404 when id is used instead of iid' do 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 diff --git a/spec/support/shared_examples/requests/api/notes.rb b/spec/support/shared_examples/requests/api/notes.rb index 4ce78d885bc..a793c23b809 100644 --- a/spec/support/shared_examples/requests/api/notes.rb +++ b/spec/support/shared_examples/requests/api/notes.rb @@ -82,7 +82,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| it "returns an array of notes" do 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(json_response).to be_an Array expect(json_response.first['body']).to eq(note.note) @@ -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 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 it "returns 404 when not authorized" do @@ -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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -107,14 +107,14 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| it "returns a note by id" do 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) end it "returns a 404 error if note not found" do 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 @@ -122,7 +122,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| it "creates a new note" do 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['author']['username']).to eq(user.username) end @@ -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 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 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!' } - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) end 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| admin = create(:admin) 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['author']['username']).to eq(admin.username) 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| 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 - 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['author']['username']).to eq(user.username) 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| 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['author']['username']).to eq(user2.username) 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| 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 - 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['author']['username']).to eq(user.username) 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| parent.add_developer(user2) 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['author']['username']).to eq(user2.username) 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| parent.add_developer(private_user) 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:') end end @@ -235,7 +235,7 @@ shared_examples 'noteable API' do |parent_type, noteable_type, id_name| it 'creates a new note' do 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:') end end @@ -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), params: { body: 'Foo' } - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end end @@ -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]}/"\ "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!') end @@ -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), params: { body: 'Hello!' } - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end it 'returns a 400 bad request error if body not given' do put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "notes/#{note.id}", user) - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(:bad_request) end end @@ -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]}/"\ "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 delete api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "notes/#{note.id}", user) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end 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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end it_behaves_like '412 response' do diff --git a/spec/support/shared_examples/requests/api/resolvable_discussions.rb b/spec/support/shared_examples/requests/api/resolvable_discussions.rb index 42054a273f3..dd764cf2d4d 100644 --- a/spec/support/shared_examples/requests/api/resolvable_discussions.rb +++ b/spec/support/shared_examples/requests/api/resolvable_discussions.rb @@ -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]}/"\ "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'][0]['resolved']).to eq(true) end @@ -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]}/"\ "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'][0]['resolved']).to eq(false) end @@ -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]}/"\ "discussions/#{note.discussion_id}", user) - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(:bad_request) end it "returns a 401 unauthorized error if user is not authenticated" do put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "discussions/#{note.discussion_id}"), params: { resolved: true } - expect(response).to have_gitlab_http_status(401) + expect(response).to have_gitlab_http_status(:unauthorized) end it "returns a 403 error if user resolves discussion of someone else" do put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 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_ put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 @@ -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]}/"\ "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) end @@ -69,21 +69,21 @@ shared_examples 'resolvable discussions API' do |parent_type, noteable_type, id_ "discussions/#{note.discussion_id}/notes/12345", user), params: { body: 'Hello!' } - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end 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]}/"\ "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 it "returns a 403 error if user resolves note of someone else" do put api("/#{parent_type}/#{parent.id}/#{noteable_type}/#{noteable[id_name]}/"\ "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 diff --git a/spec/support/shared_examples/requests/api/status_shared_examples.rb b/spec/support/shared_examples/requests/api/status_shared_examples.rb index ed9964fa108..d5845863a58 100644 --- a/spec/support/shared_examples/requests/api/status_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/status_shared_examples.rb @@ -13,7 +13,7 @@ shared_examples_for '400 response' do end it 'returns 400' do - expect(response).to have_gitlab_http_status(400) + expect(response).to have_gitlab_http_status(:bad_request) if message.present? expect(json_response['message']).to eq(message) @@ -28,7 +28,7 @@ shared_examples_for '403 response' do end it 'returns 403' do - expect(response).to have_gitlab_http_status(403) + expect(response).to have_gitlab_http_status(:forbidden) end end @@ -41,7 +41,7 @@ shared_examples_for '404 response' do end 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 if message.present? @@ -60,7 +60,7 @@ shared_examples_for '412 response' do end 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') end end diff --git a/spec/support/shared_examples/requests/rack_attack_shared_examples.rb b/spec/support/shared_examples/requests/rack_attack_shared_examples.rb index c078e982e87..a864f3ac652 100644 --- a/spec/support/shared_examples/requests/rack_attack_shared_examples.rb +++ b/spec/support/shared_examples/requests/rack_attack_shared_examples.rb @@ -33,7 +33,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do # At first, allow requests under the rate limit. requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end # the last straw @@ -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 requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end expect_rejection { make_request(request_args) } @@ -51,7 +51,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do Timecop.travel(period.from_now) do requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end expect_rejection { make_request(request_args) } @@ -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 requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end # would be over the limit if this wasn't a different user 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 it 'counts all requests from the same user, even via different IPs' do requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end 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 it 'logs RackAttack info into structured logs' do requests_per_period.times do make_request(request_args) - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end arguments = { @@ -112,7 +112,7 @@ shared_examples_for 'rate-limited token-authenticated requests' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do 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 @@ -160,7 +160,7 @@ shared_examples_for 'rate-limited web authenticated requests' do # At first, allow requests under the rate limit. requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end # the last straw @@ -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 requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end expect_rejection { request_authenticated_web_url } @@ -178,7 +178,7 @@ shared_examples_for 'rate-limited web authenticated requests' do Timecop.travel(period.from_now) do requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end expect_rejection { request_authenticated_web_url } @@ -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 requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end # would be over the limit if this wasn't a different user login_as(create(:user)) request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end it 'counts all requests from the same user, even via different IPs' do requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end 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 it 'logs RackAttack info into structured logs' do requests_per_period.times do request_authenticated_web_url - expect(response).not_to have_http_status 429 + expect(response).not_to have_gitlab_http_status(:too_many_requests) end arguments = { @@ -241,7 +241,7 @@ shared_examples_for 'rate-limited web authenticated requests' do it 'allows requests over the rate limit' do (1 + requests_per_period).times do 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 diff --git a/spec/support/shared_examples/resource_label_events_api.rb b/spec/support/shared_examples/resource_label_events_api.rb index 6622df78ee2..d3d9b83764d 100644 --- a/spec/support/shared_examples/resource_label_events_api.rb +++ b/spec/support/shared_examples/resource_label_events_api.rb @@ -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 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(json_response).to be_an Array 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_ it "returns a 404 error when eventable id not found" do 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 it "returns 404 when not authorized" do @@ -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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -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 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) end @@ -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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end 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) - expect(response).to have_gitlab_http_status(404) + expect(response).to have_gitlab_http_status(:not_found) end end @@ -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 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 diff --git a/spec/support/shared_examples/unique_ip_check_shared_examples.rb b/spec/support/shared_examples/unique_ip_check_shared_examples.rb index 9bdfa762fc8..17777f2cc93 100644 --- a/spec/support/shared_examples/unique_ip_check_shared_examples.rb +++ b/spec/support/shared_examples/unique_ip_check_shared_examples.rb @@ -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 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 |