From 00ea1bf719ad5bb5af52604b7a0a0471bc4cbd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 3 Aug 2022 15:17:49 +0200 Subject: [PATCH] Fix customization of budget_execution_no_image We forgot to change the line rendering the image in commits 3574bf867c and 810bdae37a, and so the custom image was being ignored. Note that, in the test, we're stubbing a constant instead of adding a new image. The main reason is that, if we add a new image, forks would have to change the image when they change the `VALID_IMAGES` constant; otherwise the tests would fail. --- .../executions/image_component.html.erb | 2 +- .../budgets/executions/image_component.rb | 1 + .../executions/image_component_spec.rb | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 spec/components/budgets/executions/image_component_spec.rb diff --git a/app/components/budgets/executions/image_component.html.erb b/app/components/budgets/executions/image_component.html.erb index 37b638a50..df3709290 100644 --- a/app/components/budgets/executions/image_component.html.erb +++ b/app/components/budgets/executions/image_component.html.erb @@ -3,5 +3,5 @@ <% elsif investment.image.present? %> <%= image_tag investment.image.variant(:large), alt: investment.image.title %> <% else %> - <%= image_tag "budget_execution_no_image.jpg", alt: investment.title %> + <%= image_tag image_path_for("budget_execution_no_image.jpg"), alt: investment.title %> <% end %> diff --git a/app/components/budgets/executions/image_component.rb b/app/components/budgets/executions/image_component.rb index 8b559350b..3058ee46d 100644 --- a/app/components/budgets/executions/image_component.rb +++ b/app/components/budgets/executions/image_component.rb @@ -1,5 +1,6 @@ class Budgets::Executions::ImageComponent < ApplicationComponent attr_reader :investment + delegate :image_path_for, to: :helpers def initialize(investment) @investment = investment diff --git a/spec/components/budgets/executions/image_component_spec.rb b/spec/components/budgets/executions/image_component_spec.rb new file mode 100644 index 000000000..a40d8d1ce --- /dev/null +++ b/spec/components/budgets/executions/image_component_spec.rb @@ -0,0 +1,25 @@ +require "rails_helper" + +describe Budgets::Executions::ImageComponent do + context "investment and milestone without image" do + let(:component) { Budgets::Executions::ImageComponent.new(Budget::Investment.new) } + + it "shows the default image" do + render_inline component + + expect(page).to have_css "img[src*='budget_execution_no_image']" + end + + it "shows a custom default image when available" do + stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "budget_execution_no_image" => [260, 80] }) + create(:site_customization_image, + name: "budget_execution_no_image", + image: fixture_file_upload("logo_header-260x80.png")) + + render_inline component + + expect(page).to have_css "img[src$='logo_header-260x80.png']" + expect(page).not_to have_css "img[src*='budget_execution_no_image']" + end + end +end