repository_directory_spec.rb revision 95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5
98N/Arequire 'spec_helper'
98N/A
943N/Adescribe RepositoryDirectory do
98N/A
98N/A context 'validations' do
919N/A let(:repository_directory) { FactoryGirl.build :repository_directory }
919N/A let(:repository) { repository_directory.repository }
919N/A let(:user) { repository_directory.repository.user }
919N/A
919N/A it 'should be valid' do
919N/A expect(repository_directory.valid?).to be_truthy
919N/A end
919N/A
919N/A it 'should fail without a name' do
919N/A repository_directory.name = ''
919N/A expect(repository_directory.valid?).to be_falsy
919N/A end
919N/A
919N/A it 'should fail with target_directory but without a name' do
919N/A repository_directory.target_directory = 'dir'
919N/A repository_directory.name = ''
919N/A expect(repository_directory.valid?).to be_falsy
98N/A end
98N/A
98N/A context 'existing tree entry' do
98N/A let(:dirname) { "#{repository_directory.name}-other" }
493N/A let(:filename) { 'file' }
98N/A let(:filepath) { File.join(dirname, filename) }
970N/A before do
970N/A repository.save_file_only(Tempfile.new('tempfile').path, filepath, 'message', user)
970N/A end
970N/A
98N/A it 'should fail when path is the directory' do
837N/A repository_directory.name = dirname
98N/A expect(repository_directory.valid?).to be_falsy
911N/A end
911N/A
911N/A it 'should fail when path is the file (with target_directory)' do
911N/A repository_directory.target_directory = dirname
98N/A repository_directory.name = filename
98N/A expect(repository_directory.valid?).to be_falsy
98N/A end
98N/A
963N/A it 'should fail when path is beneath the file' do
963N/A repository_directory.name = File.join(filepath, 'beneath')
98N/A expect(repository_directory.valid?).to be_falsy
98N/A end
98N/A
it 'should fail when path is beneath the file (with target_directory)' do
repository_directory.target_directory = filepath
repository_directory.name = 'beneath'
expect(repository_directory.valid?).to be_falsy
end
end
end
context 'fields' do
let(:repository_directory) { FactoryGirl.build :repository_directory }
it 'path should be target_directory plus name' do
repository_directory.target_directory = 'dir'
expect(repository_directory.target_path).
to eq(File.join(repository_directory.target_directory, repository_directory.name))
end
end
context 'directory creation' do
let(:repository_directory) { FactoryGirl.build :repository_directory }
let(:repository) { repository_directory.repository }
let(:user) { repository_directory.repository.user }
it 'should create the directory in the git repository' do
expect(repository.path_exists?(repository_directory.target_path)).to be_falsy
repository_directory.save
expect(repository.path_exists?(repository_directory.target_path)).to be_truthy
end
it 'should create the directory in the git repository in a subdirectory' do
repository_directory.target_directory = 'test'
expect(repository.path_exists?(repository_directory.target_path)).to be_falsy
repository_directory.save
expect(repository.path_exists?(repository_directory.target_path)).to be_truthy
end
it 'should create a .gitkeep file' do
repository_directory.save
expect(repository.path_exists?(File.join(repository_directory.target_path, '.gitkeep'))).
to be_truthy
end
end
end