Skip to content

Commit

Permalink
Merge pull request #1064 from sul-dlss/dvz-model-specs
Browse files Browse the repository at this point in the history
Addes rspec tests for Druid Version Zip models, closes #968
  • Loading branch information
SaravShah committed Aug 8, 2018
2 parents 2b2690a + 96f2000 commit a73c2c4
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions spec/models/druid_version_zip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,34 @@
let(:druid) { 'bj102hs9687' }
let(:version) { 1 }

describe '#base_key' do
it 'returns filename without ext' do
expect(dvz.base_key).to eq 'bj/102/hs/9687/bj102hs9687.v0001'
end
end

describe '#s3_key' do
it 'returns a tree path-based key' do
expect(dvz.s3_key).to eq 'bj/102/hs/9687/bj102hs9687.v0001.zip'
end
end

describe '#ensure_zip_directory' do
it 'returns path if zip directory exists' do
expect(dvz.ensure_zip_directory!.to_s).to eq '/tmp/bj/102/hs/9687/bj102hs9687.v0001.zip'
end

context 'zip directory does not exist' do
before { FileUtils.rm_rf('/tmp/bj/102/hs/9687/') }

it 'returns path by creating zip directory if does not exist' do
expect(File).not_to exist('/tmp/bj/102/hs/9687/bj102hs9687.v0001.zip')
expect { dvz.ensure_zip_directory! }.not_to raise_error
expect(dvz.ensure_zip_directory!.to_s).to eq '/tmp/bj/102/hs/9687/bj102hs9687.v0001.zip'
end
end
end

describe '#file_path' do
it 'returns a full path' do
expect(dvz.file_path).to eq '/tmp/bj/102/hs/9687/bj102hs9687.v0001.zip'
Expand Down Expand Up @@ -171,6 +193,28 @@
end
end

describe '#v_version' do
let(:version) { 1 }

it 'returns 3 zero-padded string of the version' do
expect(dvz.v_version).to eq 'v0001'
end

context "two digit version" do
let(:version) { 34 }

it 'returns 2 zero-padded string of the version' do
expect(dvz.v_version).to eq 'v0034'
end
end
end

describe '#work_dir' do
it 'returns Pathname directory where the zip command is executed' do
expect(dvz.work_dir.to_s).to eq 'spec/fixtures/storage_root01/sdr2objects/bj/102/hs/9687'
end
end

describe '#zip_command' do
let(:zip_path) { '/tmp/bj/102/hs/9687/bj102hs9687.v0001.zip' }

Expand Down Expand Up @@ -201,4 +245,10 @@
expect(dvz.send(:fetch_zip_version)).to match(/^Zip \d+\.\d+/)
end
end

describe '#zip_storage' do
it 'returns Pathname to location where the zip file is to be created' do
expect(dvz.zip_storage.to_s).to eq '/tmp'
end
end
end

0 comments on commit a73c2c4

Please sign in to comment.