diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 28232e9..fdac4ab 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -264,7 +264,8 @@ def upload_file(f) if config.compression compressed_name = "#{path}/#{f}.#{config.compression}" - if File.extname(f) == config.compression + # `File.extname` returns value with `.` prefix, `config.compression` contains value without `.` + if File.extname(f)[1..-1] == config.compression # Don't bother uploading compressed assets if we are in compression mode # as we will overwrite file.css with file.css.gz if it exists. log "Ignoring: #{f}" diff --git a/spec/unit/storage_spec.rb b/spec/unit/storage_spec.rb index cc7d1d3..1d68768 100644 --- a/spec/unit/storage_spec.rb +++ b/spec/unit/storage_spec.rb @@ -393,6 +393,46 @@ def check_file(file) end storage.upload_file('assets/some_longer_path/local_image2.jpg') end + + context 'config.gzip_compression is enabled' do + context 'when the file is a css file' do + it 'should upload the file' do + @config.gzip_compression = true + + storage = AssetSync::Storage.new(@config) + allow(storage).to receive(:get_local_files).and_return(@local_files) + allow(storage).to receive(:get_remote_files).and_return(@remote_files) + # Pretend they all exist + allow(File).to receive(:open).and_return(file_like_object) + bucket = double + files = double + allow(storage).to receive(:bucket).and_return(bucket) + allow(bucket).to receive(:files).and_return(files) + + expect(files).to receive(:create).with({ body: file_like_object, content_type: "text/css", key: "assets/local.css", public: true }).once + storage.upload_file('assets/local.css') + end + end + + context 'when the file is a gz file' do + it 'should not upload the file' do + @config.gzip_compression = true + + storage = AssetSync::Storage.new(@config) + allow(storage).to receive(:get_local_files).and_return(@local_files) + allow(storage).to receive(:get_remote_files).and_return(@remote_files) + # Pretend they all exist + allow(File).to receive(:open).and_return(file_like_object) + bucket = double + files = double + allow(storage).to receive(:bucket).and_return(bucket) + allow(bucket).to receive(:files).and_return(files) + + expect(files).to_not receive(:create) + storage.upload_file('assets/local.css.gz') + end + end + end end describe '#delete_extra_remote_files' do