diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 00:08:59 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 00:08:59 +0300 |
commit | d466ee5042520ad078fe050cb078d81dc2ebe196 (patch) | |
tree | 5648eb1aee8aeff5b5c5ff4669a184fd7676f778 /spec/requests | |
parent | 6a9d7c009e4e5975a89bcc3e458da4b3ec484bd1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/commits_spec.rb | 35 | ||||
-rw-r--r-- | spec/requests/api/issues/issues_spec.rb | 9 | ||||
-rw-r--r-- | spec/requests/api/merge_requests_spec.rb | 290 |
3 files changed, 151 insertions, 183 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index e390f3945a9..170b9ccccf8 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -12,7 +12,6 @@ describe API::Commits do let(:project) { create(:project, :repository, creator: user, path: 'my.project') } let(:branch_with_dot) { project.repository.find_branch('ends-with.json') } let(:branch_with_slash) { project.repository.find_branch('improve/awesome') } - let(:project_id) { project.id } let(:current_user) { nil } @@ -241,6 +240,40 @@ describe API::Commits do end end end + + context 'with order parameter' do + let(:route) { "/projects/#{project_id}/repository/commits?ref_name=0031876&per_page=6&order=#{order}" } + + context 'set to topo' do + let(:order) { 'topo' } + + # git log --graph -n 6 --pretty=format:"%h" --topo-order 0031876 + # * 0031876 + # |\ + # | * 48ca272 + # | * 335bc94 + # * | bf6e164 + # * | 9d526f8 + # |/ + # * 1039376 + it 'returns project commits ordered by topo order' do + commits = project.repository.commits("0031876", limit: 6, order: 'topo') + + get api(route, current_user) + + expect(json_response.size).to eq(6) + expect(json_response.map { |entry| entry["id"] }).to eq(commits.map(&:id)) + end + end + + context 'set to blank' do + let(:order) { '' } + + it_behaves_like '400 response' do + let(:request) { get api(route, current_user) } + end + end + end end end diff --git a/spec/requests/api/issues/issues_spec.rb b/spec/requests/api/issues/issues_spec.rb index 09e005398a9..19422d4ca39 100644 --- a/spec/requests/api/issues/issues_spec.rb +++ b/spec/requests/api/issues/issues_spec.rb @@ -795,13 +795,13 @@ describe API::Issues do it 'returns issues from non archived projects only by default' do get api("/groups/#{group1.id}/issues", user), params: { scope: 'all' } - expect_response_contain_exactly(issue2, issue1) + expect_paginated_array_response([issue2.id, issue1.id]) end it 'returns issues from archived and non archived projects when non_archived is false' do get api("/groups/#{group1.id}/issues", user), params: { non_archived: false, scope: 'all' } - expect_response_contain_exactly(issue1, issue2, issue3) + expect_paginated_array_response([issue3.id, issue2.id, issue1.id]) end end end @@ -888,9 +888,4 @@ describe API::Issues do include_examples 'time tracking endpoints', 'issue' end - - def expect_response_contain_exactly(*items) - expect(json_response.length).to eq(items.size) - expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id)) - end end diff --git a/spec/requests/api/merge_requests_spec.rb b/spec/requests/api/merge_requests_spec.rb index 427a361295c..00af0937dd7 100644 --- a/spec/requests/api/merge_requests_spec.rb +++ b/spec/requests/api/merge_requests_spec.rb @@ -41,8 +41,7 @@ describe API::MergeRequests do it 'returns merge requests for public projects' do get api(endpoint_path) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array end end @@ -87,10 +86,11 @@ describe API::MergeRequests do it 'returns an array of all merge_requests' do get api(endpoint_path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) + expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last).to have_key('web_url') expect(json_response.last['sha']).to eq(merge_request.diff_head_sha) @@ -111,7 +111,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) + expect_successful_response_with_paginated_array expect(json_response.last['labels'].pluck('name')).to eq([label2.title, label.title]) expect(json_response.last['labels'].first).to match_schema('/public_api/v4/label_basic') end @@ -139,11 +139,11 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) expect(json_response.last.keys).to match_array(%w(id iid title web_url created_at description project_id state updated_at)) - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) expect(json_response.last['iid']).to eq(merge_request.iid) expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last).to have_key('web_url') @@ -157,10 +157,10 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) expect(json_response.last['title']).to eq(merge_request.title) end @@ -169,10 +169,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(1) + expect_paginated_array_response([merge_request.id]) expect(json_response.last['title']).to eq(merge_request.title) end @@ -181,10 +178,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(1) + expect_paginated_array_response([merge_request_closed.id]) expect(json_response.first['title']).to eq(merge_request_closed.title) end @@ -193,10 +187,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(1) + expect_paginated_array_response([merge_request_merged.id]) expect(json_response.first['title']).to eq(merge_request_merged.title) end @@ -210,17 +201,13 @@ describe API::MergeRequests do it 'returns an empty array if no issue matches milestone' do get api(endpoint_path, user), params: { milestone: '1.0.0' } - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'returns an empty array if milestone does not exist' do get api(endpoint_path, user), params: { milestone: 'foo' } - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'returns an array of merge requests in given milestone' do @@ -234,9 +221,7 @@ describe API::MergeRequests do it 'returns an array of merge requests matching state in milestone' do get api(endpoint_path, user), params: { milestone: '0.9', state: 'closed' } - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(1) + expect_paginated_array_response([merge_request_closed.id]) expect(json_response.first['id']).to eq(merge_request_closed.id) end @@ -248,8 +233,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label2.title, label.title]) end @@ -259,9 +243,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'returns an empty array if no merge request matches labels' do @@ -269,9 +251,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'returns an array of labeled merge requests where all labels match' do @@ -279,8 +259,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label2.title, label.title]) end @@ -288,8 +267,7 @@ describe API::MergeRequests do it 'returns an array of merge requests with any label when filtering by any label' do get api(endpoint_path, user), params: { labels: [" #{label.title} ", " #{label2.title} "] } - expect_paginated_array_response - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['id']).to eq(merge_request.id) @@ -298,8 +276,7 @@ describe API::MergeRequests do it 'returns an array of merge requests with any label when filtering by any label' do get api(endpoint_path, user), params: { labels: ["#{label.title} , #{label2.title}"] } - expect_paginated_array_response - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['id']).to eq(merge_request.id) @@ -308,7 +285,7 @@ describe API::MergeRequests do it 'returns an array of merge requests with any label when filtering by any label' do get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_ANY } - expect_paginated_array_response + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(merge_request.id) end @@ -316,10 +293,9 @@ describe API::MergeRequests do it 'returns an array of merge requests without a label when filtering by no label' do get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_NONE } - response_ids = json_response.map { |merge_request| merge_request['id'] } - - expect_paginated_array_response - expect(response_ids).to contain_exactly(merge_request_closed.id, merge_request_merged.id, merge_request_locked.id) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, merge_request_closed.id + ]) end end @@ -339,10 +315,7 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(1) - expect(json_response.first['id']).to eq(mr2.id) + expect_paginated_array_response([mr2.id]) end context 'with ordering' do @@ -356,10 +329,10 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request_closed.id, merge_request_locked.id, + merge_request_merged.id, merge_request.id + ]) response_dates = json_response.map { |merge_request| merge_request['created_at'] } expect(response_dates).to eq(response_dates.sort) end @@ -369,10 +342,10 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request.id, merge_request_merged.id, + merge_request_locked.id, merge_request_closed.id + ]) response_dates = json_response.map { |merge_request| merge_request['created_at'] } expect(response_dates).to eq(response_dates.sort.reverse) end @@ -414,10 +387,10 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request.id, merge_request_locked.id, + merge_request_merged.id, merge_request_closed.id + ]) response_dates = json_response.map { |merge_request| merge_request['updated_at'] } expect(response_dates).to eq(response_dates.sort.reverse) end @@ -427,10 +400,10 @@ describe API::MergeRequests do get api(path, user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(4) + expect_paginated_array_response([ + merge_request_closed.id, merge_request_locked.id, + merge_request_merged.id, merge_request.id + ]) response_dates = json_response.map { |merge_request| merge_request['created_at'] } expect(response_dates).to eq(response_dates.sort) end @@ -440,7 +413,9 @@ describe API::MergeRequests do it 'returns merge requests with the given source branch' do get api(endpoint_path, user), params: { source_branch: merge_request_closed.source_branch, state: 'all' } - expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, merge_request_closed.id + ]) end end @@ -448,7 +423,9 @@ describe API::MergeRequests do it 'returns merge requests with the given target branch' do get api(endpoint_path, user), params: { target_branch: merge_request_closed.target_branch, state: 'all' } - expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, merge_request_closed.id + ]) end end end @@ -471,7 +448,10 @@ describe API::MergeRequests do it 'returns an array of all merge requests' do get api('/merge_requests', user), params: { scope: 'all' } - expect_paginated_array_response + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) end it "returns authentication error without any scope" do @@ -507,30 +487,23 @@ describe API::MergeRequests do it 'returns an array of all merge requests except unauthorized ones' do get api('/merge_requests', user), params: { scope: :all } - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.map { |mr| mr['id'] }) - .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) + expect_paginated_array_response([ + merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id + ]) end it "returns an array of no merge_requests when wip=yes" do get api("/merge_requests", user), params: { wip: 'yes' } - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it "returns an array of no merge_requests when wip=no" do get api("/merge_requests", user), params: { wip: 'no' } - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.map { |mr| mr['id'] }) - .to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id) + expect_paginated_array_response([ + merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id + ]) end it 'does not return unauthorized merge requests' do @@ -539,7 +512,9 @@ describe API::MergeRequests do get api('/merge_requests', user), params: { scope: :all } - expect_response_contain_exactly(merge_request2, merge_request_merged, merge_request_closed, merge_request, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id + ]) expect(json_response.map { |mr| mr['id'] }).not_to include(merge_request3.id) end @@ -548,7 +523,7 @@ describe API::MergeRequests do get api('/merge_requests', user2) - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests authored by the given user' do @@ -556,7 +531,7 @@ describe API::MergeRequests do get api('/merge_requests', user), params: { author_id: user2.id, scope: :all } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests assigned to the given user' do @@ -564,7 +539,7 @@ describe API::MergeRequests do get api('/merge_requests', user), params: { assignee_id: user2.id, scope: :all } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests with no assignee' do @@ -572,7 +547,7 @@ describe API::MergeRequests do get api('/merge_requests', user), params: { assignee_id: 'None', scope: :all } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests with any assignee' do @@ -581,7 +556,10 @@ describe API::MergeRequests do get api('/merge_requests', user), params: { assignee_id: 'Any', scope: :all } - expect_response_contain_exactly(merge_request, merge_request2, merge_request_closed, merge_request_merged, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request2.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) end it 'returns an array of merge requests assigned to me' do @@ -589,7 +567,7 @@ describe API::MergeRequests do get api('/merge_requests', user2), params: { scope: 'assigned_to_me' } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests assigned to me (kebab-case)' do @@ -597,7 +575,7 @@ describe API::MergeRequests do get api('/merge_requests', user2), params: { scope: 'assigned-to-me' } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests created by me' do @@ -605,7 +583,7 @@ describe API::MergeRequests do get api('/merge_requests', user2), params: { scope: 'created_by_me' } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns an array of merge requests created by me (kebab-case)' do @@ -613,7 +591,7 @@ describe API::MergeRequests do get api('/merge_requests', user2), params: { scope: 'created-by-me' } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end it 'returns merge requests reacted by the authenticated user by the given emoji' do @@ -622,14 +600,16 @@ describe API::MergeRequests do get api('/merge_requests', user2), params: { my_reaction_emoji: award_emoji.name, scope: 'all' } - expect_response_ordered_exactly(merge_request3) + expect_paginated_array_response([merge_request3.id]) end context 'source_branch param' do it 'returns merge requests with the given source branch' do get api('/merge_requests', user), params: { source_branch: merge_request_closed.source_branch, state: 'all' } - expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, merge_request_closed.id + ]) end end @@ -637,7 +617,9 @@ describe API::MergeRequests do it 'returns merge requests with the given target branch' do get api('/merge_requests', user), params: { target_branch: merge_request_closed.target_branch, state: 'all' } - expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, merge_request_closed.id + ]) end end @@ -646,7 +628,7 @@ describe API::MergeRequests do get api('/merge_requests?created_before=2000-01-02T00:00:00.060Z', user) - expect_response_ordered_exactly(merge_request2) + expect_paginated_array_response([merge_request2.id]) end it 'returns merge requests created after a specific date' do @@ -654,7 +636,7 @@ describe API::MergeRequests do get api("/merge_requests?created_after=#{merge_request2.created_at}", user) - expect_response_ordered_exactly(merge_request2) + expect_paginated_array_response([merge_request2.id]) end it 'returns merge requests updated before a specific date' do @@ -662,7 +644,7 @@ describe API::MergeRequests do get api('/merge_requests?updated_before=2000-01-02T00:00:00.060Z', user) - expect_response_ordered_exactly(merge_request2) + expect_paginated_array_response([merge_request2.id]) end it 'returns merge requests updated after a specific date' do @@ -670,7 +652,7 @@ describe API::MergeRequests do get api("/merge_requests?updated_after=#{merge_request2.updated_at}", user) - expect_response_ordered_exactly(merge_request2) + expect_paginated_array_response([merge_request2.id]) end context 'search params' do @@ -681,25 +663,25 @@ describe API::MergeRequests do it 'returns merge requests matching given search string for title' do get api("/merge_requests", user), params: { search: merge_request.title } - expect_response_ordered_exactly(merge_request) + expect_paginated_array_response([merge_request.id]) end it 'returns merge requests matching given search string for title and scoped in title' do get api("/merge_requests", user), params: { search: merge_request.title, in: 'title' } - expect_response_ordered_exactly(merge_request) + expect_paginated_array_response([merge_request.id]) end - it 'returns an empty array if no merge reques matches given search string for description and scoped in title' do + it 'returns an empty array if no merge request matches given search string for description and scoped in title' do get api("/merge_requests", user), params: { search: merge_request.description, in: 'title' } - expect_response_contain_exactly + expect_empty_array_response end it 'returns merge requests for project matching given search string for description' do get api("/merge_requests", user), params: { project_id: project.id, search: merge_request.description } - expect_response_ordered_exactly(merge_request) + expect_paginated_array_response([merge_request.id]) end end @@ -707,7 +689,7 @@ describe API::MergeRequests do it 'returns merge requests with the given state' do get api('/merge_requests', user), params: { state: 'locked' } - expect_response_contain_exactly(merge_request_locked) + expect_paginated_array_response([merge_request_locked.id]) end end end @@ -729,18 +711,13 @@ describe API::MergeRequests do it "returns an array of no merge_requests when wip=yes" do get api("/projects/#{project.id}/merge_requests", user), params: { wip: 'yes' } - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'returns merge_request by "iids" array' do get api(endpoint_path, user), params: { iids: [merge_request.iid, merge_request_closed.iid] } - expect(response).to have_gitlab_http_status(200) - expect(json_response).to be_an Array - expect(json_response.length).to eq(2) + expect_paginated_array_response([merge_request_closed.id, merge_request.id]) expect(json_response.first['title']).to eq merge_request_closed.title expect(json_response.first['id']).to eq merge_request_closed.id end @@ -815,12 +792,10 @@ describe API::MergeRequests do it 'returns an array excluding merge_requests from archived projects' do get api(endpoint_path, user) - expect_response_contain_exactly( - merge_request_merged, - merge_request_locked, - merge_request_closed, - merge_request - ) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) end context 'with non_archived param set as false' do @@ -829,13 +804,10 @@ describe API::MergeRequests do get api(path, user) - expect_response_contain_exactly( - merge_request_merged, - merge_request_locked, - merge_request_closed, - merge_request, - merge_request_archived - ) + expect_paginated_array_response([ + merge_request_merged.id, merge_request_archived.id, merge_request_locked.id, + merge_request_closed.id, merge_request.id + ]) end end end @@ -1079,9 +1051,7 @@ describe API::MergeRequests do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user) commit = merge_request.commits.first - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.size).to eq(merge_request.commits.size) expect(json_response.first['id']).to eq(commit.id) expect(json_response.first['title']).to eq(commit.title) @@ -1105,9 +1075,7 @@ describe API::MergeRequests do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.size).to eq(merge_request.context_commits.size) expect(json_response.first['id']).to eq(context_commit.id) expect(json_response.first['title']).to eq(context_commit.title) @@ -1147,9 +1115,7 @@ describe API::MergeRequests do it 'returns a paginated array of corresponding pipelines' do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines") - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.count).to eq(1) expect(json_response.first['id']).to eq(pipeline.id) end @@ -1395,7 +1361,7 @@ describe API::MergeRequests do expect(json_response['labels']).to eq([]) end - xit 'empty label param as array, does not add any labels' do + it 'empty label param as array, does not add any labels' do params[:labels] = [] post api("/projects/#{project.id}/merge_requests", user), params: params @@ -2232,7 +2198,7 @@ describe API::MergeRequests do expect(json_response['labels']).to eq [] end - xit 'empty label as array, removes labels' do + it 'empty label as array, removes labels' do put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), params: { title: 'new issue', @@ -2240,7 +2206,6 @@ describe API::MergeRequests do } expect(response.status).to eq(200) - # fails, as grape ommits for some reason empty array as optional param value, so nothing it passed along expect(json_response['labels']).to eq [] end @@ -2306,9 +2271,7 @@ describe API::MergeRequests do get api("/projects/#{project.id}/merge_requests/#{mr.iid}/closes_issues", user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(1) expect(json_response.first['id']).to eq(issue.id) end @@ -2316,10 +2279,7 @@ describe API::MergeRequests do it 'returns an empty array when there are no issues to be closed' do get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - expect(json_response.length).to eq(0) + expect_empty_array_response end it 'handles external issues' do @@ -2332,9 +2292,7 @@ describe API::MergeRequests do get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array + expect_successful_response_with_paginated_array expect(json_response.length).to eq(2) expect(json_response.second['title']).to eq(ext_issue.title) expect(json_response.second['id']).to eq(ext_issue.id) @@ -2546,22 +2504,4 @@ describe API::MergeRequests do merge_request_closed.save merge_request_closed end - - def expect_response_contain_exactly(*items) - expect_paginated_array_response - expect(json_response.length).to eq(items.size) - expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id)) - end - - def expect_response_ordered_exactly(*items) - expect_paginated_array_response - expect(json_response.length).to eq(items.size) - expect(json_response.map { |element| element['id'] }).to eq(items.map(&:id)) - end - - def expect_paginated_array_response - expect(response).to have_gitlab_http_status(200) - expect(response).to include_pagination_headers - expect(json_response).to be_an Array - end end |