2015-01-10 15:37:48 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe TreeHelper do
|
|
|
|
describe 'flatten_tree' do
|
2017-01-25 17:10:32 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2017-09-06 16:47:25 -04:00
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:sha) { 'ce369011c189f62c815f5971d096b26759bab0d1' }
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|