Move executions image partial to a component

This way it'll be easier to write tests for it. We also get rid of
another helper file :).
This commit is contained in:
Javi Martín
2022-08-03 15:14:02 +02:00
parent 4d674bf643
commit f0ab7bcfcc
4 changed files with 15 additions and 9 deletions

View File

@@ -1,5 +1,3 @@
<% milestone = first_milestone_with_image(investment) %>
<% if milestone&.image.present? %>
<%= image_tag milestone.image.variant(:large), alt: milestone.image.title %>
<% elsif investment.image.present? %>

View File

@@ -0,0 +1,14 @@
class Budgets::Executions::ImageComponent < ApplicationComponent
attr_reader :investment
def initialize(investment)
@investment = investment
end
private
def milestone
investment.milestones.order_by_publication_date
.select { |milestone| milestone.image.present? }.last
end
end

View File

@@ -1,6 +0,0 @@
module BudgetExecutionsHelper
def first_milestone_with_image(investment)
investment.milestones.order_by_publication_date
.select { |milestone| milestone.image.present? }.last
end
end

View File

@@ -7,7 +7,7 @@
<div class="small-12 medium-6 large-4 column end margin-bottom">
<div class="budget-execution">
<%= link_to budget_investment_path(@budget, investment, anchor: "tab-milestones"), data: { "equalizer-watch": true } do %>
<%= render "image", investment: investment %>
<%= render Budgets::Executions::ImageComponent.new(investment) %>
<div class="budget-execution-info">
<div class="budget-execution-content">
<h5><%= investment.title %></h5>