2015-04-26 12:48:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe TreeHelper do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:sha) { 'ce369011c189f62c815f5971d096b26759bab0d1' }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe '.render_tree' do
|
2015-09-11 14:41:01 +05:30
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
@id = sha
|
2018-05-09 12:01:36 +05:30
|
|
|
@path = ""
|
2018-03-17 18:26:18 +05:30
|
|
|
@project = project
|
|
|
|
@lfs_blob_ids = []
|
|
|
|
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)
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'flatten_tree' do
|
|
|
|
let(:tree) { repository.tree(sha, 'files') }
|
|
|
|
let(:root_path) { 'files' }
|
|
|
|
let(:tree_item) { tree.entries.find { |entry| entry.path == path } }
|
|
|
|
|
|
|
|
subject { flatten_tree(root_path, tree_item) }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
context "on a directory containing more than one file/directory" do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:path) { 'files/html' }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns the directory name" do
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(subject).to match('html')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "on a directory containing only one directory" do
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:path) { 'files/flat' }
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns the flattened path" do
|
2018-03-17 18:26:18 +05:30
|
|
|
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-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
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-04-26 12:48:37 +05:30
|
|
|
end
|
2018-03-27 19:54:05 +05:30
|
|
|
|
|
|
|
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-04-26 12:48:37 +05:30
|
|
|
end
|