2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2012-09-17 16:38:59 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2013-06-23 17:25:06 +00:00
|
|
|
describe Projects::TreeController do
|
2017-01-25 21:44:33 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
2012-09-17 16:38:59 +00:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2012-09-17 16:38:59 +00:00
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET show" do
|
|
|
|
# Make sure any errors accessing the tree in our views bubble up to this spec
|
|
|
|
render_views
|
|
|
|
|
2015-01-24 18:02:58 +00:00
|
|
|
before do
|
2019-04-08 03:55:29 +00:00
|
|
|
expect(::Gitlab::GitalyClient).to receive(:allow_ref_name_caching).and_call_original
|
|
|
|
|
2015-06-23 05:24:39 +00:00
|
|
|
get(:show,
|
2018-12-17 22:52:17 +00:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
})
|
2015-01-24 18:02:58 +00:00
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
|
|
|
|
context "valid branch, no path" do
|
|
|
|
let(:id) { 'master' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to respond_with(:success) }
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "valid branch, valid path" do
|
2014-08-07 17:46:17 +00:00
|
|
|
let(:id) { 'master/encoding/' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to respond_with(:success) }
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "valid branch, invalid path" do
|
2013-04-03 12:55:08 +00:00
|
|
|
let(:id) { 'master/invalid-path/' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
|
|
|
it 'redirects' do
|
|
|
|
expect(subject)
|
2019-12-17 18:07:48 +00:00
|
|
|
.to redirect_to("/#{project.full_path}/-/tree/master")
|
2019-10-21 18:06:29 +00:00
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "invalid branch, valid path" do
|
2014-08-07 17:46:17 +00:00
|
|
|
let(:id) { 'invalid-branch/encoding/' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
it { is_expected.to respond_with(:not_found) }
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
2015-07-20 23:55:45 +00:00
|
|
|
|
|
|
|
context "valid empty branch, invalid path" do
|
|
|
|
let(:id) { 'empty-branch/invalid-path/' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
|
|
|
it 'redirects' do
|
|
|
|
expect(subject)
|
2019-12-17 18:07:48 +00:00
|
|
|
.to redirect_to("/#{project.full_path}/-/tree/empty-branch")
|
2019-10-21 18:06:29 +00:00
|
|
|
end
|
2015-07-20 23:55:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context "valid empty branch" do
|
|
|
|
let(:id) { 'empty-branch' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-07-20 23:55:45 +00:00
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "invalid SHA commit ID" do
|
|
|
|
let(:id) { 'ff39438/.gitignore' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-07-20 23:55:45 +00:00
|
|
|
it { is_expected.to respond_with(:not_found) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "valid SHA commit ID" do
|
|
|
|
let(:id) { '6d39438' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-07-20 23:55:45 +00:00
|
|
|
it { is_expected.to respond_with(:success) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "valid SHA commit ID with path" do
|
|
|
|
let(:id) { '6d39438/.gitignore' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2017-10-19 18:28:19 +00:00
|
|
|
it { expect(response).to have_gitlab_http_status(302) }
|
2015-07-20 23:55:45 +00:00
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|
2014-07-08 18:25:25 +00:00
|
|
|
|
2018-12-26 07:34:47 +00:00
|
|
|
describe 'GET show with whitespace in ref' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
let(:id) { "this ref/api/responses" }
|
|
|
|
|
|
|
|
it 'does not call make a Gitaly request' do
|
|
|
|
allow(::Gitlab::GitalyClient).to receive(:call).and_call_original
|
|
|
|
expect(::Gitlab::GitalyClient).not_to receive(:call).with(anything, :commit_service, :find_commit, anything, anything)
|
|
|
|
|
|
|
|
get(:show,
|
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-08 18:25:25 +00:00
|
|
|
describe 'GET show with blob path' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
2015-06-23 05:24:39 +00:00
|
|
|
get(:show,
|
2018-12-17 22:52:17 +00:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: id
|
|
|
|
})
|
2014-07-08 18:25:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'redirect to blob' do
|
|
|
|
let(:id) { 'master/README.md' }
|
2019-10-21 18:06:29 +00:00
|
|
|
|
2015-02-12 18:53:23 +00:00
|
|
|
it 'redirects' do
|
2019-12-17 18:07:48 +00:00
|
|
|
redirect_url = "/#{project.full_path}/-/blob/master/README.md"
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(subject)
|
|
|
|
.to redirect_to(redirect_url)
|
2015-02-12 18:53:23 +00:00
|
|
|
end
|
2014-07-08 18:25:25 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-17 05:45:22 +00:00
|
|
|
|
|
|
|
describe '#create_dir' do
|
|
|
|
render_views
|
|
|
|
|
|
|
|
before do
|
|
|
|
post(:create_dir,
|
2018-12-17 22:52:17 +00:00
|
|
|
params: {
|
|
|
|
namespace_id: project.namespace.to_param,
|
|
|
|
project_id: project,
|
|
|
|
id: 'master',
|
|
|
|
dir_name: path,
|
|
|
|
branch_name: branch_name,
|
|
|
|
commit_message: 'Test commit message'
|
|
|
|
})
|
2015-09-17 05:45:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'successful creation' do
|
|
|
|
let(:path) { 'files/new_dir'}
|
2017-04-20 00:37:44 +00:00
|
|
|
let(:branch_name) { 'master-test'}
|
2015-09-17 05:45:22 +00:00
|
|
|
|
|
|
|
it 'redirects to the new directory' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(subject)
|
2019-12-17 18:07:48 +00:00
|
|
|
.to redirect_to("/#{project.full_path}/-/tree/#{branch_name}/#{path}")
|
2015-12-18 09:03:34 +00:00
|
|
|
expect(flash[:notice]).to eq('The directory has been successfully created.')
|
2015-09-17 05:45:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'unsuccessful creation' do
|
|
|
|
let(:path) { 'README.md' }
|
2017-04-20 00:37:44 +00:00
|
|
|
let(:branch_name) { 'master'}
|
2015-09-17 05:45:22 +00:00
|
|
|
|
|
|
|
it 'does not allow overwriting of existing files' do
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(subject)
|
2019-12-17 18:07:48 +00:00
|
|
|
.to redirect_to("/#{project.full_path}/-/tree/master")
|
2017-04-20 00:37:44 +00:00
|
|
|
expect(flash[:alert]).to eq('A file with this name already exists')
|
2015-09-17 05:45:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-17 16:38:59 +00:00
|
|
|
end
|