From 87c275a1f7b493cdbbab06d7b9a775e5168e2764 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jun 2022 15:30:07 +1000 Subject: [PATCH 1/2] Spec order confirmation page --- .../views/spree/orders/show.html.haml_spec.rb | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 spec/views/spree/orders/show.html.haml_spec.rb diff --git a/spec/views/spree/orders/show.html.haml_spec.rb b/spec/views/spree/orders/show.html.haml_spec.rb new file mode 100644 index 0000000000..48bed635d6 --- /dev/null +++ b/spec/views/spree/orders/show.html.haml_spec.rb @@ -0,0 +1,59 @@ +# 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 + pending "https://github.com/openfoodfoundation/openfoodnetwork/issues/9279" + + 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 From bec2a873decb51260df67d661a0aff9ba4e0c6e8 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 10 Jun 2022 15:32:58 +1000 Subject: [PATCH 2/2] Show order and admin page despite broken image Avoiding: ActiveStorage::InvariableError Affects the admin order page and the customer's order confirmation page. --- app/views/spree/shared/_variant_thumbnail.html.haml | 7 +------ spec/views/spree/orders/show.html.haml_spec.rb | 2 -- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/app/views/spree/shared/_variant_thumbnail.html.haml b/app/views/spree/shared/_variant_thumbnail.html.haml index d92e205a0b..12c2589984 100644 --- a/app/views/spree/shared/_variant_thumbnail.html.haml +++ b/app/views/spree/shared/_variant_thumbnail.html.haml @@ -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") diff --git a/spec/views/spree/orders/show.html.haml_spec.rb b/spec/views/spree/orders/show.html.haml_spec.rb index 48bed635d6..1b9a2882cf 100644 --- a/spec/views/spree/orders/show.html.haml_spec.rb +++ b/spec/views/spree/orders/show.html.haml_spec.rb @@ -43,8 +43,6 @@ describe "spree/orders/show.html.haml" do end it "handles broken images" do - pending "https://github.com/openfoodfoundation/openfoodnetwork/issues/9279" - image, = order.line_items.first.variant.product.images << Spree::Image.new( attachment: fixture_file_upload("logo.png", "image/png") )