Skip to content

Commit

Permalink
fix issue not working optipng interlace option, resolves #136
Browse files Browse the repository at this point in the history
  • Loading branch information
mrk21 committed Aug 1, 2016
1 parent 690d917 commit 1d3aa63
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## unreleased

* Add proper handling of `ImageOptim.respond_to?` [@toy](https://github.com/toy)
* 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)

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 1d3aa63

Please sign in to comment.