diff --git a/spec/lib/zipline/zip_generator_spec.rb b/spec/lib/zipline/zip_generator_spec.rb index 5213cbf..442d243 100644 --- a/spec/lib/zipline/zip_generator_spec.rb +++ b/spec/lib/zipline/zip_generator_spec.rb @@ -185,91 +185,4 @@ def create_filename end end end - - describe '.write_file' do - let(:file) { StringIO.new('passthrough') } - - context 'when passing an ActiveStorage::Filename object as filename' do - let(:filename) { ActiveStorage::Filename.new('test') } - - let(:generator) do - Zipline::ZipGenerator.new([[file, filename]]) - end - - it 'passes a string as filename to ZipTricks' do - allow(file).to receive(:url).and_return('fakeurl') - expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file) - .with('test') - generator.each { |_| 'Test' } - end - end - end - - describe 'passing an options hash' do - let(:file) { StringIO.new('passthrough') } - - context 'with optional arguments' do - let(:mtime) { 1.day.ago } - let(:generator) do - Zipline::ZipGenerator.new([[file, 'test', modification_time: mtime]]) - end - - it 'passes the options hash through handle_file' do - expect(generator).to receive(:handle_file) - .with(anything, anything, anything, { modification_time: mtime }) - generator.each { |_| 'Test' } - end - - it 'passes the options hash to ZipTricks as kwargs' do - allow(file).to receive(:url).and_return('fakeurl') - expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file) - .with(anything, modification_time: mtime) - generator.each { |_| 'Test' } - end - end - - context 'without optional arguments' do - let(:generator) do - Zipline::ZipGenerator.new([[file, 'test']]) - end - - it 'passes the options hash through handle_file' do - expect(generator).to receive(:handle_file) - .with(anything, anything, anything, {}) - generator.each { |_| 'Test' } - end - - it 'passes the options hash to ZipTricks as kwargs' do - allow(file).to receive(:url).and_return('fakeurl') - expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file) - .with(anything) - generator.each { |_| 'Test' } - end - end - - context 'with extra invalid options' do - let(:mtime) { 1.day.ago } - let(:generator) do - Zipline::ZipGenerator.new([[file, 'test', modification_time: mtime, extra: 'invalid']]) - end - - it 'passes the whole options hash through handle_file' do - expect(generator).to receive(:handle_file) - .with(anything, anything, anything, { modification_time: mtime, extra: 'invalid' }) - generator.each { |_| 'Test' } - end - - it 'only passes the kwargs to ZipTricks that it expects (i.e., :modification_time)' do - allow(file).to receive(:url).and_return('fakeurl') - expect_any_instance_of(ZipTricks::Streamer).to receive(:write_deflated_file) - .with(anything, modification_time: mtime) - generator.each { |_| 'Test' } - end - end - end - it 'passes along constructor options to ZipTricks streamer' do - expect(ZipTricks::Streamer).to receive(:open).with(anything, { :some => 'options' }) - generator = Zipline::ZipGenerator.new([file, 'somefile'], :some => 'options') - generator.each { |_| 'Test' } - end end