summaryrefslogtreecommitdiff
path: root/spec/requests
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2018-03-28 14:24:05 +0000
committerRémy Coutable <remy@rymai.me>2018-03-28 14:24:05 +0000
commitfffa19cbb623e42d2cea5369e3c853f1ee96033e (patch)
tree863ce3f1101704d28638e08cb16461353dbc1cc5 /spec/requests
parentd7a9df68329bee42a4f2c4934351022c949f7c71 (diff)
parent847671e06c13155c02d8f0be3565705cd89969ee (diff)
downloadgitlab-ce-fffa19cbb623e42d2cea5369e3c853f1ee96033e.tar.gz
Merge branch 'expose-commits-mr-api' into 'master'
Allow merge requests related to a commit to be found via API See merge request gitlab-org/gitlab-ce!18004
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/commits_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 852f67db958..8ad19e3f0f5 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -1141,4 +1141,33 @@ describe API::Commits do
end
end
end
+
+ describe 'GET /projects/:id/repository/commits/:sha/merge_requests' do
+ let!(:project) { create(:project, :repository, :private) }
+ let!(:merged_mr) { create(:merge_request, source_project: project, source_branch: 'master', target_branch: 'feature') }
+ let(:commit) { merged_mr.merge_request_diff.commits.last }
+
+ it 'returns the correct merge request' do
+ get api("/projects/#{project.id}/repository/commits/#{commit.id}/merge_requests", user)
+
+ expect(response).to have_gitlab_http_status(200)
+ expect(response).to include_pagination_headers
+ expect(json_response.length).to eq(1)
+ expect(json_response[0]['id']).to eq(merged_mr.id)
+ end
+
+ it 'returns 403 for an unauthorized user' do
+ project.add_guest(user)
+
+ get api("/projects/#{project.id}/repository/commits/#{commit.id}/merge_requests", user)
+
+ expect(response).to have_gitlab_http_status(403)
+ end
+
+ it 'responds 404 when the commit does not exist' do
+ get api("/projects/#{project.id}/repository/commits/a7d26f00c35b/merge_requests", user)
+
+ expect(response).to have_gitlab_http_status(404)
+ end
+ end
end