2012-09-25 23:40:04 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-06-23 13:25:06 -04:00
|
|
|
describe Projects::CommitsController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2013-04-25 10:15:33 -04:00
|
|
|
let(:user) { create(:user) }
|
2012-09-25 23:40:04 -04:00
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2012-09-25 23:40:04 -04:00
|
|
|
end
|
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context 'signed in' do
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET commits_root" do
|
|
|
|
context "no ref is provided" do
|
|
|
|
it 'should redirect to the default branch of the project' do
|
|
|
|
get(:commits_root,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project
|
|
|
|
})
|
2018-07-23 20:04:16 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
expect(response).to redirect_to project_commits_path(project)
|
|
|
|
end
|
2018-07-23 20:04:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
describe "GET show" do
|
|
|
|
render_views
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context 'with file path' do
|
|
|
|
before do
|
|
|
|
get(:show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
})
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context "valid branch, valid file" do
|
|
|
|
let(:id) { 'master/README.md' }
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context "valid branch, invalid file" do
|
|
|
|
let(:id) { 'master/invalid-path.rb' }
|
2016-10-07 11:49:48 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context "invalid branch, valid file" do
|
|
|
|
let(:id) { 'invalid-branch/README.md' }
|
2017-10-01 10:54:12 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
2018-12-10 00:23:15 -05:00
|
|
|
|
|
|
|
context "branch with invalid format, valid file" do
|
|
|
|
let(:id) { 'branch with space/README.md' }
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
2017-10-01 10:54:12 -04:00
|
|
|
end
|
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context "when the ref name ends in .atom" do
|
|
|
|
context "when the ref does not exist with the suffix" do
|
|
|
|
before do
|
|
|
|
get(:show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: "master.atom"
|
|
|
|
})
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "renders as atom" do
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(response.content_type).to eq('application/atom+xml')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders summary with type=html' do
|
|
|
|
expect(response.body).to include('<summary type="html">')
|
|
|
|
end
|
2018-01-21 06:06:48 -05:00
|
|
|
end
|
2016-10-07 11:49:48 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context "when the ref exists with the suffix" do
|
|
|
|
before do
|
|
|
|
commit = project.repository.commit('master')
|
2018-01-21 06:06:48 -05:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
allow_any_instance_of(Repository).to receive(:commit).and_call_original
|
|
|
|
allow_any_instance_of(Repository).to receive(:commit).with('master.atom').and_return(commit)
|
|
|
|
|
|
|
|
get(:show,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: "master.atom"
|
|
|
|
})
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "renders as HTML" do
|
|
|
|
expect(response).to be_success
|
|
|
|
expect(response.content_type).to eq('text/html')
|
|
|
|
end
|
2018-01-21 06:06:48 -05:00
|
|
|
end
|
2016-10-07 11:49:48 -04:00
|
|
|
end
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
2018-12-10 00:23:15 -05:00
|
|
|
|
|
|
|
describe "GET /commits/:id/signatures" do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
get(:signatures,
|
2018-12-17 17:52:17 -05:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
},
|
2018-12-10 00:23:15 -05:00
|
|
|
format: :json)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "valid branch" do
|
|
|
|
let(:id) { 'master' }
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "invalid branch format" do
|
|
|
|
let(:id) { 'some branch' }
|
|
|
|
|
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
|
|
|
end
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
2016-10-07 11:49:48 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
context 'token authentication' do
|
|
|
|
context 'public project' do
|
|
|
|
it_behaves_like 'authenticates sessionless user', :show, :atom, public: true do
|
2016-10-07 11:49:48 -04:00
|
|
|
before do
|
2018-11-28 14:06:02 -05:00
|
|
|
public_project = create(:project, :repository, :public)
|
2016-10-07 11:49:48 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
default_params.merge!(namespace_id: public_project.namespace, project_id: public_project, id: "master.atom")
|
2016-10-07 11:49:48 -04:00
|
|
|
end
|
2018-11-28 14:06:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'private project' do
|
|
|
|
it_behaves_like 'authenticates sessionless user', :show, :atom, public: false do
|
|
|
|
before do
|
|
|
|
private_project = create(:project, :repository, :private)
|
|
|
|
private_project.add_maintainer(user)
|
2016-10-07 11:49:48 -04:00
|
|
|
|
2018-11-28 14:06:02 -05:00
|
|
|
default_params.merge!(namespace_id: private_project.namespace, project_id: private_project, id: "master.atom")
|
2016-10-07 11:49:48 -04:00
|
|
|
end
|
2012-09-25 23:40:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|