Skip to content

Commit

Permalink
Increasing the code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Apr 24, 2020
1 parent b80c29f commit 6871366
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions spec/change_set_persisters/change_set_persister_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,35 +409,54 @@
described_class.new(metadata_adapter: adapter, storage_adapter: storage_adapter, characterize: true)
end

context "when uploading files from the cloud" do
context "when uploading files from the cloud", run_real_characterization: false, run_real_derivatives: false do
let(:file) do
PendingUpload.new(
id: SecureRandom.uuid,
upload_id: "test-upload-id",
upload_file_id: "https://www.example.com/resource1/1.tif"
)
end
let(:binary_file) { fixture_file_upload("files/example.tif", "image/tiff") }
let(:bytestream) { instance_double(ActiveStorage::Blob) }
let(:upload_file) { double }
let(:upload_file_id) { "https://www.example.com/resource1/1.tif" }
let(:pending_upload) { PendingUpload.new(upload_file_id: upload_file_id) }

before do
allow(upload_file).to receive(:bytestream).and_return(bytestream)
allow(upload_file).to receive(:purge_bytestream)
allow(upload_file).to receive(:name).and_return("example.tif")
allow(upload_file).to receive(:id).and_return(upload_file_id)
allow(BrowseEverything::UploadFile).to receive(:find).and_return([upload_file])
allow(upload_file).to receive(:download).and_raise(StandardError)
end

it "does not append files when the upload fails", run_real_derivatives: true do
resource = FactoryBot.build(:scanned_resource)
it "persists the files" do
allow(upload_file).to receive(:download).and_return(File.read(binary_file))
resource = FactoryBot.build(:scanned_resource, pending_uploads: [pending_upload])
change_set = change_set_class.new(resource, characterize: false, ocr_language: ["eng"])
change_set.files = [file]

output = change_set_persister.save(change_set: change_set)
members = query_service.find_members(resource: output)

expect(members.to_a.length).to eq 0
expect(members.to_a.length).to eq 1
end

context "when the download fails" do
before do
allow(upload_file).to receive(:download).and_raise(StandardError)
end

it "does not append files when the upload fails", run_real_derivatives: true do
resource = FactoryBot.build(:scanned_resource)
change_set = change_set_class.new(resource, characterize: false, ocr_language: ["eng"])
change_set.files = [file]

output = change_set_persister.save(change_set: change_set)
members = query_service.find_members(resource: output)

expect(members.to_a.length).to eq 0
end
end
end

Expand Down

0 comments on commit 6871366

Please sign in to comment.