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

Rescue FileNotFoundError exception on failed image downloads #4026

Merged
merged 1 commit into from
Apr 15, 2021
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
15 changes: 15 additions & 0 deletions backend/spec/features/admin/products/edit/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
expect(page).not_to have_field "image[alt]", with: "ruby on rails t-shirt"
end

context 'Using Active Storage',
if: Spree::Config.image_attachment_module == Spree::Image::ActiveStorageAttachment do
it "should show a no image placeholder when images fail to download" do
click_link "new_image_link"
within_fieldset 'New Image' do
attach_file('image_attachment', file_path)
end

click_button "Update"
Spree::Image.first.attachment.blob.update(key: 11)
visit current_path
expect(page).to have_xpath("//img[contains(@src, 'assets/noimage/mini')]")
end
end

context "with several variants" do
it "should allow an admin to re-assign an image to another variant" do
click_link "new_image_link"
Expand Down
2 changes: 2 additions & 0 deletions core/app/models/concerns/spree/active_storage_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def filename

def url(style = default_style)
attachment.url(style)
rescue ActiveStorage::FileNotFoundError
"noimage/#{style}.png"
end

def destroy_attachment(_name)
Expand Down