Skip to content

Commit

Permalink
Fix failing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sandbergja committed Jul 12, 2023
1 parent 2baa2d8 commit 06f7a6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Rename files to .processed when we download them
* See if we can share code with POD

* Fetch the file(s) that is there
* Unzip the file
* Create a tempfile file with the namespace added. lib_jobs/app/models/marc_collection.rb
* Make the record fixes
Expand Down
15 changes: 11 additions & 4 deletions spec/models/alma_submit_collection/alma_recap_file_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
let(:file_attributes) { instance_double("Net::SFTP::Protocol::V01::Attributes") }
let(:sftp_session) { instance_double("Net::SFTP::Session", dir: sftp_dir) }
let(:sftp_dir) { instance_double("Net::SFTP::Operations::Dir") }
let(:sftp_file_factory) { Net::SFTP::Operations::FileFactory.new(sftp_session) }
let(:file_size) { 1028 }

before do
allow(file_attributes).to receive(:size).and_return file_size
allow(file_name).to receive(:attributes).and_return file_attributes
allow(sftp_dir).to receive(:foreach).and_yield file_name
allow(sftp_session).to receive(:file).and_return StringIO
allow(sftp_session).to receive(:file).and_return sftp_file_factory
allow(sftp_file_factory).to receive(:open).and_return StringIO.new
allow(Net::SFTP).to receive(:start).and_yield sftp_session
end

Expand All @@ -40,10 +42,15 @@
end

describe '#download_and_decompress_file' do
pending 'we need to decompress the fixture file before checking, also get a smaller file'
before do
allow(sftp_file_factory).to receive(:open).and_return File.new(Pathname.new(file_fixture_path).join("alma", alma_recap_filename))
end
it 'downloads and returns the content of the file' do
results = alma_recap_file_list.download_and_decompress_file(alma_recap_filename)
expect(results.first.readlines).to eq(File.new(Pathname.new(file_fixture_path).join("alma", alma_recap_filename)).readlines)
title_field = '<datafield tag="245" ind1="1" ind2="0"><subfield code="a">Distress in the fields :</subfield>'\
'<subfield code="b">Indian agriculture after liberalization /</subfield>'\
'<subfield code="c">edited by R. Ramakumar.</subfield></datafield>'
decompressed_file_contents = alma_recap_file_list.download_and_decompress_file(alma_recap_filename)
expect(decompressed_file_contents.first.string).to include(title_field)
end
end
end

0 comments on commit 06f7a6f

Please sign in to comment.