|
| 1 | +require_relative 'spec_helper' |
| 2 | +require_relative '../lib/object_dirs_helper' |
| 3 | + |
| 4 | +describe ObjectDirsHelper do |
| 5 | + before do |
| 6 | + allow(Dir).to receive(:pwd).and_return('/home/git/repositories/foo/bar.git') |
| 7 | + end |
| 8 | + |
| 9 | + describe '.all_attributes' do |
| 10 | + it do |
| 11 | + expect(described_class.all_attributes.keys).to include(*%w[ |
| 12 | + GIT_OBJECT_DIRECTORY |
| 13 | + GIT_OBJECT_DIRECTORY_RELATIVE |
| 14 | + GIT_ALTERNATE_OBJECT_DIRECTORIES |
| 15 | + GIT_ALTERNATE_OBJECT_DIRECTORIES_RELATIVE |
| 16 | + ]) |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + describe '.absolute_object_dir' do |
| 21 | + subject { described_class.absolute_object_dir } |
| 22 | + |
| 23 | + context 'when GIT_OBJECT_DIRECTORY is set' do |
| 24 | + let(:dir) { '/home/git/repositories/foo/bar.git/./objects' } |
| 25 | + |
| 26 | + before do |
| 27 | + allow(ENV).to receive(:[]).with('GIT_OBJECT_DIRECTORY').and_return(dir) |
| 28 | + end |
| 29 | + |
| 30 | + it { expect(subject).to eq(dir) } |
| 31 | + end |
| 32 | + |
| 33 | + context 'when GIT_OBJECT_DIRECTORY is not set' do |
| 34 | + it { expect(subject).to be_nil } |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + describe '.absolute_alt_object_dirs' do |
| 39 | + subject { described_class.absolute_alt_object_dirs } |
| 40 | + |
| 41 | + context 'when GIT_ALTERNATE_OBJECT_DIRECTORIES is set' do |
| 42 | + let(:dirs) { [ |
| 43 | + '/home/git/repositories/foo/bar.git/./incoming-UKU6Gl', |
| 44 | + '/home/git/repositories/foo/bar.git/./incoming-AcU7Qr' |
| 45 | + ] } |
| 46 | + |
| 47 | + before do |
| 48 | + allow(ENV).to receive(:[]).with('GIT_ALTERNATE_OBJECT_DIRECTORIES').and_return(dirs.join(File::PATH_SEPARATOR)) |
| 49 | + end |
| 50 | + |
| 51 | + it { expect(subject).to eq(dirs) } |
| 52 | + end |
| 53 | + |
| 54 | + context 'when GIT_ALTERNATE_OBJECT_DIRECTORIES is not set' do |
| 55 | + it { expect(subject).to eq([]) } |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + describe '.relative_alt_object_dirs' do |
| 60 | + subject { described_class.relative_alt_object_dirs } |
| 61 | + |
| 62 | + context 'when GIT_ALTERNATE_OBJECT_DIRECTORIES is set' do |
| 63 | + let(:dirs) { [ |
| 64 | + '/home/git/repositories/foo/bar.git/./objects/incoming-UKU6Gl', |
| 65 | + '/home/git/repositories/foo/bar.git/./objects/incoming-AcU7Qr' |
| 66 | + ] } |
| 67 | + |
| 68 | + before do |
| 69 | + allow(ENV).to receive(:[]).with('GIT_ALTERNATE_OBJECT_DIRECTORIES').and_return(dirs.join(File::PATH_SEPARATOR)) |
| 70 | + end |
| 71 | + |
| 72 | + it { expect(subject).to eq(['objects/incoming-UKU6Gl', 'objects/incoming-AcU7Qr']) } |
| 73 | + end |
| 74 | + |
| 75 | + context 'when GIT_ALTERNATE_OBJECT_DIRECTORIES is not set' do |
| 76 | + it { expect(subject).to eq([]) } |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + describe '.relative_object_dir' do |
| 81 | + subject { described_class.relative_object_dir } |
| 82 | + |
| 83 | + context 'when GIT_OBJECT_DIRECTORY is set' do |
| 84 | + before do |
| 85 | + allow(ENV).to receive(:[]).with('GIT_OBJECT_DIRECTORY').and_return('/home/git/repositories/foo/bar.git/./objects') |
| 86 | + end |
| 87 | + |
| 88 | + it { expect(subject).to eq('objects') } |
| 89 | + end |
| 90 | + |
| 91 | + context 'when GIT_OBJECT_DIRECTORY is not set' do |
| 92 | + it { expect(subject).to be_nil } |
| 93 | + end |
| 94 | + end |
| 95 | +end |
0 commit comments