2015-01-10 15:37:48 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe TreeHelper do
|
2017-11-10 15:39:00 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
2018-10-17 20:03:15 -04:00
|
|
|
let(:sha) { 'c1c67abbaf91f624347bb3ae96eabe3a1b742478' }
|
2017-11-10 15:39:00 -05:00
|
|
|
|
|
|
|
describe '.render_tree' do
|
|
|
|
before do
|
|
|
|
@id = sha
|
2018-04-04 09:56:41 -04:00
|
|
|
@path = ""
|
2017-11-10 15:39:00 -05:00
|
|
|
@project = project
|
2017-12-14 06:31:50 -05:00
|
|
|
@lfs_blob_ids = []
|
2017-11-10 15:39:00 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'displays all entries without a warning' do
|
|
|
|
tree = repository.tree(sha, 'files')
|
|
|
|
|
|
|
|
html = render_tree(tree)
|
|
|
|
|
|
|
|
expect(html).not_to have_selector('.tree-truncated-warning')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'truncates entries and adds a warning' do
|
|
|
|
stub_const('TreeHelper::FILE_LIMIT', 1)
|
|
|
|
tree = repository.tree(sha, 'files')
|
|
|
|
|
|
|
|
html = render_tree(tree)
|
|
|
|
|
|
|
|
expect(html).to have_selector('.tree-truncated-warning', count: 1)
|
|
|
|
expect(html).to have_selector('.tree-item-file-name', count: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-17 20:03:15 -04:00
|
|
|
describe '.fast_project_blob_path' do
|
|
|
|
it 'generates the same path as project_blob_path' do
|
|
|
|
blob_path = repository.tree(sha, 'with space').entries.first.path
|
|
|
|
fast_path = fast_project_blob_path(project, blob_path)
|
|
|
|
std_path = project_blob_path(project, blob_path)
|
|
|
|
|
|
|
|
expect(fast_path).to eq(std_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates the same path with encoded file names' do
|
|
|
|
tree = repository.tree(sha, 'encoding')
|
|
|
|
blob_path = tree.entries.find { |entry| entry.path == 'encoding/テスト.txt' }.path
|
|
|
|
fast_path = fast_project_blob_path(project, blob_path)
|
|
|
|
std_path = project_blob_path(project, blob_path)
|
|
|
|
|
|
|
|
expect(fast_path).to eq(std_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'respects a configured relative URL' do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
|
|
|
|
blob_path = repository.tree(sha, '').entries.first.path
|
|
|
|
fast_path = fast_project_blob_path(project, blob_path)
|
|
|
|
|
|
|
|
expect(fast_path).to start_with('/gitlab/root')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.fast_project_tree_path' do
|
|
|
|
let(:tree_path) { repository.tree(sha, 'with space').path }
|
|
|
|
let(:fast_path) { fast_project_tree_path(project, tree_path) }
|
|
|
|
let(:std_path) { project_tree_path(project, tree_path) }
|
|
|
|
|
|
|
|
it 'generates the same path as project_tree_path' do
|
|
|
|
expect(fast_path).to eq(std_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'respects a configured relative URL' do
|
|
|
|
allow(Gitlab.config.gitlab).to receive(:relative_url_root).and_return('/gitlab/root')
|
|
|
|
|
|
|
|
expect(fast_path).to start_with('/gitlab/root')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-10 15:37:48 -05:00
|
|
|
describe 'flatten_tree' do
|
2017-09-06 16:47:25 -04:00
|
|
|
let(:tree) { repository.tree(sha, 'files') }
|
|
|
|
let(:root_path) { 'files' }
|
|
|
|
let(:tree_item) { tree.entries.find { |entry| entry.path == path } }
|
2015-01-10 15:37:48 -05:00
|
|
|
|
2017-09-06 16:47:25 -04:00
|
|
|
subject { flatten_tree(root_path, tree_item) }
|
2015-01-10 15:37:48 -05:00
|
|
|
|
|
|
|
context "on a directory containing more than one file/directory" do
|
2017-09-06 16:47:25 -04:00
|
|
|
let(:path) { 'files/html' }
|
2015-01-10 15:37:48 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "returns the directory name" do
|
2017-09-06 16:47:25 -04:00
|
|
|
expect(subject).to match('html')
|
2015-01-10 15:37:48 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a directory containing only one directory" do
|
2017-09-06 16:47:25 -04:00
|
|
|
let(:path) { 'files/flat' }
|
2015-01-10 15:37:48 -05:00
|
|
|
|
2016-07-25 14:16:19 -04:00
|
|
|
it "returns the flattened path" do
|
2017-09-06 16:47:25 -04:00
|
|
|
expect(subject).to match('flat/path/correct')
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a nested root path" do
|
|
|
|
let(:root_path) { 'files/flat' }
|
|
|
|
|
|
|
|
it "returns the flattened path with the root path suffix removed" do
|
|
|
|
expect(subject).to match('path/correct')
|
|
|
|
end
|
2015-01-10 15:37:48 -05:00
|
|
|
end
|
|
|
|
end
|
2018-04-04 09:56:41 -04:00
|
|
|
|
|
|
|
context 'when the root path contains a plus character' do
|
|
|
|
let(:root_path) { 'gtk/C++' }
|
|
|
|
let(:tree_item) { double(flat_path: 'gtk/C++/glade') }
|
|
|
|
|
|
|
|
it 'returns the flattened path' do
|
|
|
|
expect(subject).to eq('glade')
|
|
|
|
end
|
|
|
|
end
|
2015-01-10 15:37:48 -05:00
|
|
|
end
|
2018-02-28 03:06:18 -05:00
|
|
|
|
|
|
|
describe '#commit_in_single_accessible_branch' do
|
|
|
|
it 'escapes HTML from the branch name' do
|
|
|
|
helper.instance_variable_set(:@branch_name, "<script>alert('escape me!');</script>")
|
|
|
|
escaped_branch_name = '<script>alert('escape me!');</script>'
|
|
|
|
|
|
|
|
expect(helper.commit_in_single_accessible_branch).to include(escaped_branch_name)
|
|
|
|
end
|
|
|
|
end
|
2015-01-10 15:37:48 -05:00
|
|
|
end
|