Skip to content

Commit

Permalink
Tests for the new job and MSR method wrapping it
Browse files Browse the repository at this point in the history
  • Loading branch information
atz committed Aug 7, 2018
1 parent 764f3e6 commit 4b5c471
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/moab_storage_root.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def validate_expired_checksums!
# Use a queue to check all associated CompleteMoab objects for C2M
def c2m_check!(last_checked_b4_date = Time.current)
complete_moabs.least_recent_version_audit(last_checked_b4_date).find_each do |cm|
CatalogToMoabJob.new(cm, storage_location).perform_later
CatalogToMoabJob.perform_later(cm, storage_location)
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/jobs/catalog_to_moab_job_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

describe CatalogToMoabJob, type: :job do
let(:job) { described_class.new(cm) }
let(:cm) { create :complete_moab }
let(:storage_dir) { 'foobar' }

describe '#perform' do
let(:validator) { instance_double(Audit::CatalogToMoab) }

it 'calls Audit::CatalogToMoab#check_catalog_version' do
expect(validator).to receive(:check_catalog_version)
expect(Audit::CatalogToMoab).to receive(:new).with(cm, storage_dir).and_return(validator)
job.perform(cm, storage_dir)
end
end
end
28 changes: 21 additions & 7 deletions spec/models/moab_storage_root_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,28 @@
end
end

describe '#validate_expired_checksums!' do
it 'calls ChecksumValidationJob for each eligible CompleteMoab' do
context 'job wrappers' do
let(:msr) { create(:moab_storage_root) }

before do
allow(Rails.logger).to receive(:info)
ms_root = create(:moab_storage_root)
ms_root.complete_moabs = build_list(:complete_moab, 2)
expect(ChecksumValidationJob).to receive(:perform_later).with(ms_root.complete_moabs.first)
expect(ChecksumValidationJob).to receive(:perform_later).with(ms_root.complete_moabs.second)
ms_root.validate_expired_checksums!
msr.complete_moabs = build_list(:complete_moab, 2)
end

describe '#validate_expired_checksums!' do
it 'calls ChecksumValidationJob for each eligible CompleteMoab' do
expect(ChecksumValidationJob).to receive(:perform_later).with(msr.complete_moabs.first)
expect(ChecksumValidationJob).to receive(:perform_later).with(msr.complete_moabs.second)
msr.validate_expired_checksums!
end
end

describe '#c2m_check!' do
it 'calls CatalogToMoabJob for each eligible CompleteMoab' do
expect(CatalogToMoabJob).to receive(:perform_later).with(msr.complete_moabs.first, msr.storage_location)
expect(CatalogToMoabJob).to receive(:perform_later).with(msr.complete_moabs.second, msr.storage_location)
msr.c2m_check!
end
end
end
end

0 comments on commit 4b5c471

Please sign in to comment.