Merge pull request #9288 from mkllnk/9279-image-order-display

Show order and admin page despite broken image
This commit is contained in:
jibees
2022-06-10 10:01:27 +02:00
committed by GitHub
2 changed files with 58 additions and 6 deletions

View File

@@ -1,6 +1 @@
- if variant.product.images.length == 0
= image_tag("/noimage/mini.png")
- else
- # A Rails bug makes it necessary to call `main_app.url_for` here.
- # https://github.com/rails/rails/issues/31325
= image_tag(main_app.url_for(variant.product.images.first.variant(:mini)))
= image_tag(variant.product.images.first&.url(:mini) || "/noimage/mini.png")

View File

@@ -0,0 +1,57 @@
# frozen_string_literal: true
require "spec_helper"
describe "spree/orders/show.html.haml" do
helper InjectionHelper
helper ShopHelper
helper ApplicationHelper
helper CheckoutHelper
helper SharedHelper
helper FooterLinksHelper
helper MarkdownHelper
helper TermsAndConditionsHelper
let(:order) {
create(
:completed_order_with_fees,
number: "R123456789",
)
}
before do
assign(:order, order)
allow(view).to receive_messages(
current_order: order,
last_payment_method: nil,
)
end
it "shows the order number" do
render
expect(rendered).to have_content("R123456789")
end
it "shows product images" do
order.line_items.first.variant.product.images << Spree::Image.new(
attachment: fixture_file_upload("logo.png", "image/png")
)
render
expect(rendered).to have_css("img[src*='logo.png']")
end
it "handles broken images" do
image, = order.line_items.first.variant.product.images << Spree::Image.new(
attachment: fixture_file_upload("logo.png", "image/png")
)
# This image is not "variable" and can't be resized:
image.attachment.blob.update!(content_type: "application/octet-stream")
render
expect(rendered).to have_no_css("img[src*='logo.png']")
expect(rendered).to have_content("R123456789")
end
end