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.
This commit is contained in:
Javi Martín
2022-08-03 15:17:49 +02:00
parent f0ab7bcfcc
commit 00ea1bf719
3 changed files with 27 additions and 1 deletions

View File

@@ -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 %>

View File

@@ -1,5 +1,6 @@
class Budgets::Executions::ImageComponent < ApplicationComponent
attr_reader :investment
delegate :image_path_for, to: :helpers
def initialize(investment)
@investment = investment

View File

@@ -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