Skip to content

Commit

Permalink
Merge pull request solidusio#4026 from nebulab/Issue-4017-FileNotFound
Browse files Browse the repository at this point in the history
Patch for FileNotFoundError bug on failed image downloads.
  • Loading branch information
kennyadsl authored Apr 15, 2021
2 parents e09aef7 + af78b4b commit 3ba6bc6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 3ba6bc6

Please sign in to comment.