Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-12 14:19:35 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-11-12 14:19:35 +0300
commit940ed58e768af5580f65159c4040541f29663d4a (patch)
tree0331605d7b5ac22be0c971e1f64452703bdeacce /spec
parentc58edd7c708c39a6e7c60bd96c7f97ced370f304 (diff)
parent430758653ce7e4d32b40648e6263b79c2709bdad (diff)
Merge branch 'commit-comments' of https://gitlab.com/jeroenj/gitlab-ce into jeroenj/gitlab-ce-commit-comments
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: CHANGELOG
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/commits_spec.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 38e0a284c36..a3f58f50913 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -8,6 +8,7 @@ describe API::API, api: true do
let!(:project) { create(:project, creator_id: user.id) }
let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) }
let!(:guest) { create(:project_member, user: user2, project: project, access_level: ProjectMember::GUEST) }
+ let!(:note) { create(:note_on_commit, author: user, project: project, commit_id: project.repository.commit.id, note: 'a comment on a commit') }
before { project.team << [user, :reporter] }
@@ -81,4 +82,68 @@ describe API::API, api: true do
end
end
end
+
+ describe 'GET /projects:id/repository/commits/:sha/comments' do
+ context 'authorized user' do
+ it 'should return merge_request comments' do
+ get api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.length.should == 1
+ json_response.first['note'].should == 'a comment on a commit'
+ json_response.first['author']['id'].should == user.id
+ end
+
+ it 'should return a 404 error if merge_request_id not found' do
+ get api("/projects/#{project.id}/repository/commits/1234ab/comments", user)
+ response.status.should == 404
+ end
+ end
+
+ context 'unauthorized user' do
+ it 'should not return the diff of the selected commit' do
+ get api("/projects/#{project.id}/repository/commits/1234ab/comments")
+ response.status.should == 401
+ end
+ end
+ end
+
+ describe 'POST /projects:id/repository/commits/:sha/comments' do
+ context 'authorized user' do
+ it 'should return comment' do
+ post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user), note: 'My comment'
+ response.status.should == 201
+ json_response['note'].should == 'My comment'
+ json_response['path'].should be_nil
+ json_response['line'].should be_nil
+ json_response['line_type'].should 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'
+ response.status.should == 201
+ json_response['note'].should == 'My comment'
+ json_response['path'].should == project.repository.commit.diffs.first.new_path
+ json_response['line'].should == 7
+ json_response['line_type'].should == 'new'
+ end
+
+ it 'should return 400 if note is missing' do
+ post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments", user)
+ response.status.should == 400
+ end
+
+ it 'should return 404 if note is attached to non existent commit' do
+ post api("/projects/#{project.id}/repository/commits/1234ab/comments", user), note: 'My comment'
+ response.status.should == 404
+ end
+ end
+
+ context 'unauthorized user' do
+ it 'should not return the diff of the selected commit' do
+ post api("/projects/#{project.id}/repository/commits/#{project.repository.commit.id}/comments")
+ response.status.should == 401
+ end
+ end
+ end
end