debian-mirror-gitlab/spec/requests/api/repositories_spec.rb

177 lines
6.6 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
require 'mime/types'
describe API::API, api: true do
include ApiHelpers
include RepoHelpers
2016-06-02 11:05:42 +05:30
include WorkhorseHelpers
2014-09-02 18:07:02 +05:30
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:project) { create(:project, creator_id: user.id) }
2016-06-02 11:05:42 +05:30
let!(:master) { create(:project_member, :master, user: user, project: project) }
let!(:guest) { create(:project_member, :guest, user: user2, project: project) }
2014-09-02 18:07:02 +05:30
describe "GET /projects/:id/repository/tree" do
context "authorized user" do
before { project.team << [user2, :reporter] }
2016-09-13 17:45:13 +05:30
it "returns project commits" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/tree", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
2016-11-03 12:29:30 +05:30
expect(json_response.first['name']).to eq('bar')
2015-04-26 12:48:37 +05:30
expect(json_response.first['type']).to eq('tree')
expect(json_response.first['mode']).to eq('040000')
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 for unknown ref' do
2015-04-26 12:48:37 +05:30
get api("/projects/#{project.id}/repository/tree?ref_name=foo", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Object
json_response['message'] == '404 Tree Not Found'
2014-09-02 18:07:02 +05:30
end
end
context "unauthorized user" do
2016-09-13 17:45:13 +05:30
it "does not return project commits" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/tree")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
end
end
describe "GET /projects/:id/repository/blobs/:sha" do
2016-09-13 17:45:13 +05:30
it "gets the raw file contents" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.md", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns 404 for invalid branch_name" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/blobs/invalid_branch_name?filepath=README.md", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns 404 for invalid file" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/blobs/master?filepath=README.invalid", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns a 400 error if filepath is missing" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/blobs/master", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(400)
2014-09-02 18:07:02 +05:30
end
end
describe "GET /projects/:id/repository/commits/:sha/blob" do
2016-09-13 17:45:13 +05:30
it "gets the raw file contents" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/commits/master/blob?filepath=README.md", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2014-09-02 18:07:02 +05:30
end
end
describe "GET /projects/:id/repository/raw_blobs/:sha" do
2016-09-13 17:45:13 +05:30
it "gets the raw file contents" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/raw_blobs/#{sample_blob.oid}", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 for unknown blob' do
2015-04-26 12:48:37 +05:30
get api("/projects/#{project.id}/repository/raw_blobs/123456", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Object
json_response['message'] == '404 Blob Not Found'
2014-09-02 18:07:02 +05:30
end
end
describe "GET /projects/:id/repository/archive(.:format)?:sha" do
2016-09-13 17:45:13 +05:30
it "gets the archive" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/archive", user)
repo_name = project.repository.name.gsub("\.git", "")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
type, params = workhorse_send_data
expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.gz/)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "gets the archive.zip" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/archive.zip", user)
repo_name = project.repository.name.gsub("\.git", "")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
type, params = workhorse_send_data
expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.zip/)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "gets the archive.tar.bz2" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/archive.tar.bz2", user)
repo_name = project.repository.name.gsub("\.git", "")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
type, params = workhorse_send_data
expect(type).to eq('git-archive')
expect(params['ArchivePath']).to match(/#{repo_name}\-[^\.]+\.tar.bz2/)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "returns 404 for invalid sha" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/archive/?sha=xxx", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
describe 'GET /projects/:id/repository/compare' do
2016-09-13 17:45:13 +05:30
it "compares branches" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'feature'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "compares tags" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/compare", user), from: 'v1.0.0', to: 'v1.1.0'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "compares commits" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.id, to: sample_commit.parent_id
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['commits']).to be_empty
expect(json_response['diffs']).to be_empty
expect(json_response['compare_same_ref']).to be_falsey
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "compares commits in reverse order" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/compare", user), from: sample_commit.parent_id, to: sample_commit.id
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['commits']).to be_present
expect(json_response['diffs']).to be_present
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it "compares same refs" do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/compare", user), from: 'master', to: 'master'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['commits']).to be_empty
expect(json_response['diffs']).to be_empty
expect(json_response['compare_same_ref']).to be_truthy
2014-09-02 18:07:02 +05:30
end
end
describe 'GET /projects/:id/repository/contributors' do
2016-09-13 17:45:13 +05:30
it 'returns valid data' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/repository/contributors", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
2014-09-02 18:07:02 +05:30
contributor = json_response.first
2016-11-03 12:29:30 +05:30
expect(contributor['email']).to eq('tiagonbotelho@hotmail.com')
expect(contributor['name']).to eq('tiagonbotelho')
expect(contributor['commits']).to eq(1)
2015-04-26 12:48:37 +05:30
expect(contributor['additions']).to eq(0)
expect(contributor['deletions']).to eq(0)
2014-09-02 18:07:02 +05:30
end
end
end