Skip to content

Commit

Permalink
Do not keep empty strings as crop values in essence picture url options
Browse files Browse the repository at this point in the history
Having empty strings as EssencePicture crop value (`crop_from` or `crop_size`) causes imagemagick to not crop the image but resize only.

Fixes #1279
  • Loading branch information
tvdeyen committed Nov 3, 2017
1 parent e6b0c6d commit b99edce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/alchemy/essence_picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ def picture_url_options

{
format: picture.default_render_format,
crop_from: crop_from,
crop_size: crop_size
crop_from: crop_from.presence,
crop_size: crop_size.presence
}.with_indifferent_access
end

Expand Down
13 changes: 13 additions & 0 deletions spec/models/alchemy/essence_picture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ module Alchemy
end
end

# Regression spec for issue #1279
context 'with crop sizes being empty strings' do
before do
expect(essence).to receive(:crop_size) { '' }
expect(essence).to receive(:crop_from) { '' }
end

it "does not include these crop sizes.", :aggregate_failures do
expect(picture_url_options[:crop_from]).to be_nil
expect(picture_url_options[:crop_size]).to be_nil
end
end

context 'without picture assigned' do
let(:picture) { nil }

Expand Down

0 comments on commit b99edce

Please sign in to comment.