summaryrefslogtreecommitdiff
path: root/spec/requests/api/commits_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/commits_spec.rb')
-rw-r--r--spec/requests/api/commits_spec.rb63
1 files changed, 40 insertions, 23 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 5219c808791..7ca75d77673 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -17,7 +17,7 @@ describe API::API, api: true do
context "authorized user" do
before { project.team << [user2, :reporter] }
- it "should return project commits" do
+ it "returns project commits" do
get api("/projects/#{project.id}/repository/commits", user)
expect(response).to have_http_status(200)
@@ -27,14 +27,14 @@ describe API::API, api: true do
end
context "unauthorized user" do
- it "should not return project commits" do
+ it "does not return project commits" do
get api("/projects/#{project.id}/repository/commits")
expect(response).to have_http_status(401)
end
end
context "since optional parameter" do
- it "should return project commits since provided parameter" do
+ it "returns project commits since provided parameter" do
commits = project.repository.commits("master")
since = commits.second.created_at
@@ -47,7 +47,7 @@ describe API::API, api: true do
end
context "until optional parameter" do
- it "should return project commits until provided parameter" do
+ it "returns project commits until provided parameter" do
commits = project.repository.commits("master")
before = commits.second.created_at
@@ -60,7 +60,7 @@ describe API::API, api: true do
end
context "invalid xmlschema date parameters" do
- it "should return an invalid parameter error message" do
+ it "returns an invalid parameter error message" do
get api("/projects/#{project.id}/repository/commits?since=invalid-date", user)
expect(response).to have_http_status(400)
@@ -71,34 +71,51 @@ describe API::API, api: true do
describe "GET /projects:id/repository/commits/:sha" do
context "authorized user" do
- it "should return a commit by sha" do
+ it "returns a commit by sha" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
+
expect(response).to have_http_status(200)
expect(json_response['id']).to eq(project.repository.commit.id)
expect(json_response['title']).to eq(project.repository.commit.title)
+ expect(json_response['stats']['additions']).to eq(project.repository.commit.stats.additions)
+ expect(json_response['stats']['deletions']).to eq(project.repository.commit.stats.deletions)
+ expect(json_response['stats']['total']).to eq(project.repository.commit.stats.total)
end
- it "should return a 404 error if not found" do
+ it "returns a 404 error if not found" do
get api("/projects/#{project.id}/repository/commits/invalid_sha", user)
expect(response).to have_http_status(404)
end
- it "should return nil for commit without CI" do
+ it "returns nil for commit without CI" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
+
expect(response).to have_http_status(200)
expect(json_response['status']).to be_nil
end
- it "should return status for CI" do
+ it "returns status for CI" do
pipeline = project.ensure_pipeline(project.repository.commit.sha, 'master')
+ pipeline.update(status: 'success')
+
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
+
expect(response).to have_http_status(200)
expect(json_response['status']).to eq(pipeline.status)
end
+
+ it "returns status for CI when pipeline is created" do
+ project.ensure_pipeline(project.repository.commit.sha, 'master')
+
+ get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}", user)
+
+ expect(response).to have_http_status(200)
+ expect(json_response['status']).to be_nil
+ end
end
context "unauthorized user" do
- it "should not return the selected commit" do
+ it "does not return the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}")
expect(response).to have_http_status(401)
end
@@ -109,7 +126,7 @@ describe API::API, api: true do
context "authorized user" do
before { project.team << [user2, :reporter] }
- it "should return the diff of the selected commit" do
+ it "returns the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff", user)
expect(response).to have_http_status(200)
@@ -118,14 +135,14 @@ describe API::API, api: true do
expect(json_response.first.keys).to include "diff"
end
- it "should return a 404 error if invalid commit" do
+ it "returns a 404 error if invalid commit" do
get api("/projects/#{project.id}/repository/commits/invalid_sha/diff", user)
expect(response).to have_http_status(404)
end
end
context "unauthorized user" do
- it "should not return the diff of the selected commit" do
+ it "does not return the diff of the selected commit" do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/diff")
expect(response).to have_http_status(401)
end
@@ -134,7 +151,7 @@ describe API::API, api: true do
describe 'GET /projects:id/repository/commits/:sha/comments' do
context 'authorized user' do
- it 'should return merge_request comments' do
+ it 'returns merge_request comments' do
get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
@@ -143,14 +160,14 @@ describe API::API, api: true do
expect(json_response.first['author']['id']).to eq(user.id)
end
- it 'should return a 404 error if merge_request_id not found' do
+ it 'returns a 404 error if merge_request_id not found' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments", user)
expect(response).to have_http_status(404)
end
end
context 'unauthorized user' do
- it 'should not return the diff of the selected commit' do
+ it 'does not return the diff of the selected commit' do
get api("/projects/#{project.id}/repository/commits/1234ab/comments")
expect(response).to have_http_status(401)
end
@@ -159,7 +176,7 @@ describe API::API, api: true do
describe 'POST /projects:id/repository/commits/:sha/comments' do
context 'authorized user' do
- it 'should return comment' do
+ it 'returns comment' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment'
expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment')
@@ -168,28 +185,28 @@ describe API::API, api: true do
expect(json_response['line_type']).to be_nil
end
- it 'should return the inline comment' do
- post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.diffs.first.new_path, line: 7, line_type: 'new'
+ it 'returns the inline comment' do
+ post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment', path: project.repository.commit.raw_diffs.first.new_path, line: 7, line_type: 'new'
expect(response).to have_http_status(201)
expect(json_response['note']).to eq('My comment')
- expect(json_response['path']).to eq(project.repository.commit.diffs.first.new_path)
+ expect(json_response['path']).to eq(project.repository.commit.raw_diffs.first.new_path)
expect(json_response['line']).to eq(7)
expect(json_response['line_type']).to eq('new')
end
- it 'should return 400 if note is missing' do
+ it 'returns 400 if note is missing' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
expect(response).to have_http_status(400)
end
- it 'should return 404 if note is attached to non existent commit' do
+ it 'returns 404 if note is attached to non existent commit' do
post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment'
expect(response).to have_http_status(404)
end
end
context 'unauthorized user' do
- it 'should not return the diff of the selected commit' do
+ it 'does not return the diff of the selected commit' do
post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments")
expect(response).to have_http_status(401)
end