8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksarequire 'spec_helper'
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksadescribe RepositoryDirectory do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa context 'validations' do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:repository_directory) { FactoryGirl.build :repository_directory }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:repository) { repository_directory.repository }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:user) { repository_directory.repository.user }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa it 'should be valid' do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa expect(repository_directory.valid?).to be_truthy
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa it 'should fail without a name' do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa repository_directory.name = ''
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa expect(repository_directory.valid?).to be_falsy
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa it 'should fail with target_directory but without a name' do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa repository_directory.target_directory = 'dir'
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa repository_directory.name = ''
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa expect(repository_directory.valid?).to be_falsy
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa context 'existing tree entry' do
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:dirname) { "#{repository_directory.name}-other" }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:filename) { 'file' }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa let(:filepath) { File.join(dirname, filename) }
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase let(:save_operation) do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase file = Tempfile.new('tempfile').path
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository.save_file_only(file, filepath, 'message', user)
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase it 'should add a commit' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase expect { save_operation }.to change { Commit.all.length }.by(1)
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase context 'failures' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase before do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase save_operation
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase end
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase it 'should fail when path is the directory' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.name = dirname
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase expect(repository_directory.valid?).to be_falsy
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase end
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase it 'should fail when path is the file (with target_directory)' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.target_directory = dirname
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.name = filename
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase expect(repository_directory.valid?).to be_falsy
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase end
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase it 'should fail when path is beneath the file' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.name = File.join(filepath, 'beneath')
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase expect(repository_directory.valid?).to be_falsy
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase it 'should fail when path is beneath the file (with target_directory)' do
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.target_directory = filepath
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase repository_directory.name = 'beneath'
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase expect(repository_directory.valid?).to be_falsy
1b6bde1f14614dff0f17325686d5c80b7ac37f1cTim Reddehase end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa context 'fields' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa let(:repository_directory) { FactoryGirl.build :repository_directory }
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa it 'path should be target_directory plus name' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa repository_directory.target_directory = 'dir'
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository_directory.target_path).
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa to eq(File.join(repository_directory.target_directory, repository_directory.name))
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa context 'directory creation' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa let(:repository_directory) { FactoryGirl.build :repository_directory }
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa let(:repository) { repository_directory.repository }
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa let(:user) { repository_directory.repository.user }
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa it 'should create the directory in the git repository' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository.path_exists?(repository_directory.target_path)).to be_falsy
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa repository_directory.save
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository.path_exists?(repository_directory.target_path)).to be_truthy
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa it 'should create the directory in the git repository in a subdirectory' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa repository_directory.target_directory = 'test'
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository.path_exists?(repository_directory.target_path)).to be_falsy
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa repository_directory.save
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository.path_exists?(repository_directory.target_path)).to be_truthy
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa it 'should create a .gitkeep file' do
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa repository_directory.save
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa expect(repository.path_exists?(File.join(repository_directory.target_path, '.gitkeep'))).
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa to be_truthy
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
95a1bcea5bd4cddc4c3dbbdf4dbcf85020fbc8d5Eugen Kuksa end
8c899e0a18a27d8717479b84cadd1f0a7883f031Eugen Kuksaend