diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 12:08:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-20 12:08:32 +0300 |
commit | 2ee5991b42717969af93cb30d863aafab04dff8a (patch) | |
tree | c09c0b7b4d02ceb9d6ac090c1ccfb93effb8a368 /spec/support/shared_examples/requests | |
parent | 6b1ba27ef7373815ea29dc5b80eab846c8acd022 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_examples/requests')
8 files changed, 99 insertions, 99 deletions
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 |