Skip to content

Commit

Permalink
fix issue not working optipng interlace option, resolves toy#136
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk21 committed Jul 28, 2016
1 parent 674b137 commit d37e43a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## unreleased

* Fix an issue not working OptiPNG `interlace` option [#136](https://github.com/toy/image_optim/pull/136) [@mrk21](https://github.com/mrk21)

## v0.23.0 (2016-07-17)

* Added `cache_dir` and `cache_worker_digests` options to cache results [#83](https://github.com/toy/image_optim/issues/83) [@gpakosz](https://github.com/gpakosz)
Expand Down
4 changes: 4 additions & 0 deletions lib/image_optim/worker/optipng.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def optimize(src, dst)
end
execute(:optipng, *args) && optimized?(src, dst)
end

def optimized?(src, dst)
interlace ? dst.size? : super
end
end
end
end
44 changes: 44 additions & 0 deletions spec/image_optim/worker/optipng_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,48 @@
end
end
end

describe '#optimized?' do
let(:src){ instance_double(ImageOptim::Path, src_options) }
let(:dst){ instance_double(ImageOptim::Path, dst_options) }
let(:src_options){ {:size? => 10, :size => 10} }
let(:dst_options){ {:size? => 9, :size => 9} }
let(:instance){ described_class.new(ImageOptim.new, instance_options) }
let(:instance_options){ {} }

subject{ instance.optimized?(src, dst) }

context 'when interlace option is enabled' do
let(:instance_options){ {:interlace => true} }

context 'when dst is empty' do
let(:dst_options){ {:size? => nil} }
it{ is_expected.to be_falsy }
end

context 'when dst is not empty' do
let(:dst_options){ {:size? => 20, :size => 20} }
it{ is_expected.to be_truthy }
end
end

context 'when interlace option is disabled' do
let(:instance_options){ {:interlace => false} }

context 'when dst is empty' do
let(:dst_options){ {:size? => nil} }
it{ is_expected.to be_falsy }
end

context 'when dst is greater than or equal to src' do
let(:dst_options){ {:size? => 10, :size => 10} }
it{ is_expected.to be_falsy }
end

context 'when dst is less than src' do
let(:dst_options){ {:size? => 9, :size => 9} }
it{ is_expected.to be_truthy }
end
end
end
end

0 comments on commit d37e43a

Please sign in to comment.