Skip to content

Commit 666a97f

Browse files
committed
Merge remote-tracking branch 'origin/pull/136'
2 parents 690d917 + 1d3aa63 commit 666a97f

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## unreleased
44

55
* Add proper handling of `ImageOptim.respond_to?` [@toy](https://github.com/toy)
6+
* Fix an issue not working OptiPNG `interlace` option [#136](https://github.com/toy/image_optim/pull/136) [@mrk21](https://github.com/mrk21)
67

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

lib/image_optim/worker/optipng.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def optimize(src, dst)
4242
end
4343
execute(:optipng, *args) && optimized?(src, dst)
4444
end
45+
46+
def optimized?(src, dst)
47+
interlace ? dst.size? : super
48+
end
4549
end
4650
end
4751
end

spec/image_optim/worker/optipng_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,48 @@
5555
end
5656
end
5757
end
58+
59+
describe '#optimized?' do
60+
let(:src){ instance_double(ImageOptim::Path, src_options) }
61+
let(:dst){ instance_double(ImageOptim::Path, dst_options) }
62+
let(:src_options){ {:size? => 10, :size => 10} }
63+
let(:dst_options){ {:size? => 9, :size => 9} }
64+
let(:instance){ described_class.new(ImageOptim.new, instance_options) }
65+
let(:instance_options){ {} }
66+
67+
subject{ instance.optimized?(src, dst) }
68+
69+
context 'when interlace option is enabled' do
70+
let(:instance_options){ {:interlace => true} }
71+
72+
context 'when dst is empty' do
73+
let(:dst_options){ {:size? => nil} }
74+
it{ is_expected.to be_falsy }
75+
end
76+
77+
context 'when dst is not empty' do
78+
let(:dst_options){ {:size? => 20, :size => 20} }
79+
it{ is_expected.to be_truthy }
80+
end
81+
end
82+
83+
context 'when interlace option is disabled' do
84+
let(:instance_options){ {:interlace => false} }
85+
86+
context 'when dst is empty' do
87+
let(:dst_options){ {:size? => nil} }
88+
it{ is_expected.to be_falsy }
89+
end
90+
91+
context 'when dst is greater than or equal to src' do
92+
let(:dst_options){ {:size? => 10, :size => 10} }
93+
it{ is_expected.to be_falsy }
94+
end
95+
96+
context 'when dst is less than src' do
97+
let(:dst_options){ {:size? => 9, :size => 9} }
98+
it{ is_expected.to be_truthy }
99+
end
100+
end
101+
end
58102
end

0 commit comments

Comments
 (0)