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 Paperclip::Errors::NotIdentifiedByImageMagickError on invalid images #2064

Merged
merged 1 commit into from
Jul 7, 2017
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
2 changes: 1 addition & 1 deletion core/app/models/spree/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Image < Asset

# save the w,h of the original image (from which others can be calculated)
# we need to look at the write-queue for images which have not been saved yet
after_post_process :find_dimensions
after_post_process :find_dimensions, if: :valid?

# used by admin products autocomplete
def mini_url
Expand Down
23 changes: 23 additions & 0 deletions core/spec/models/spree/image_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe Spree::Image, type: :model do
context '#save' do
context 'invalid attachment' do
let(:invalid_image) { File.open(__FILE__) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

And congrats on the first tests on the Image model : )

subject { described_class.new(attachment: invalid_image) }

it 'returns false' do
expect(subject.save).to be false
end
end

context 'valid attachment' do
let(:valid_image) { File.open(File.join('spec', 'fixtures', 'thinking-cat.jpg')) }
subject { described_class.new(attachment: valid_image) }

it 'returns true' do
expect(subject.save).to be true
end
end
end
end