diff options
author | Robert Schilling <rschilling@student.tugraz.at> | 2017-10-24 18:02:08 +0300 |
---|---|---|
committer | Robert Schilling <rschilling@student.tugraz.at> | 2018-02-09 15:25:06 +0300 |
commit | 2bbf75f2114530f499bb1a917f000c7605d147f1 (patch) | |
tree | 5ae43fc9204837410ef2f8b2ca8b347b6a8a19ab /spec/requests/api/commits_spec.rb | |
parent | cea2a8f741d623ca2085e8149112de3a20a4779f (diff) |
Start with tests
Diffstat (limited to 'spec/requests/api/commits_spec.rb')
-rw-r--r-- | spec/requests/api/commits_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index ff5f207487b..964dd7ad39e 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -465,6 +465,66 @@ describe API::Commits do end end + describe 'GET /projects/:id/repository/commits/:sha/refs' do + let(:project) { create(:project, :public, :repository) } + let(:tag) { project.repository.find_tag('v1.1.0') } + let(:commit_id) { tag.dereferenced_target.id } + let(:route) { "/projects/#{project_id}/repository/commits/#{commit_id}/refs" } + + context 'when ref does not exist' do + let(:commit_id) { 'unknown' } + + it_behaves_like '404 response' do + let(:request) { get api(route, current_user) } + let(:message) { '404 Commit Not Found' } + end + end + + context 'when repository is disabled' do + include_context 'disabled repository' + + it_behaves_like '403 response' do + let(:request) { get api(route, current_user) } + end + end + + context 'for a valid commit' do + it 'returns all refs with no scope' do + get api(route, current_user) + + repo_refs = project.repository.branch_names_contains(commit_id) + repo_refs.push(*project.repository.tag_names_contains(commit_id)) + + expect(json_response.map { |refs| refs['name'] }).to eq(repo_refs) + end + + it 'returns all refs' do + get api(route, current_user), type: 'all' + + repo_refs = project.repository.branch_names_contains(commit_id) + repo_refs.push(*project.repository.tag_names_contains(commit_id)) + + expect(json_response.map { |refs| refs['name'] }).to eq(repo_refs) + end + + it 'returns the branch refs' do + get api(route, current_user), type: 'branches' + + repo_refs = project.repository.branch_names_contains(commit_id) + + expect(json_response.map { |refs| refs['name'] }).to eq(repo_refs) + end + + it 'returns the tag refs' do + get api(route, current_user), type: 'tags' + + repo_refs = project.repository.tag_names_contains(commit_id) + + expect(json_response.map { |refs| refs['name'] }).to eq(repo_refs) + end + end + end + describe 'GET /projects/:id/repository/commits/:sha' do let(:commit) { project.repository.commit } let(:commit_id) { commit.id } |