Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix wrong condition #437

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
PikachuEXE marked this conversation as resolved.
Show resolved Hide resolved
# 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}"
Expand Down
40 changes: 40 additions & 0 deletions spec/unit/storage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down