From 0c09fd22af5007662917238bc453d10c4ee3afdf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?=
<15726+Senen@users.noreply.github.com>
Date: Fri, 13 Jan 2023 13:51:32 +0100
Subject: [PATCH] Do not show the `Evaluate` link when there are no projects to
evaluate for current valuator
---
.../valuation/budgets/row_component.html.erb | 10 ++++----
.../valuation/budgets/row_component.rb | 6 ++---
.../valuation/budgets/row_component_spec.rb | 23 +++++++++++++++++++
spec/system/admin/budget_investments_spec.rb | 1 +
4 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/app/components/valuation/budgets/row_component.html.erb b/app/components/valuation/budgets/row_component.html.erb
index 7489b50af..5ba9933f8 100644
--- a/app/components/valuation/budgets/row_component.html.erb
+++ b/app/components/valuation/budgets/row_component.html.erb
@@ -6,11 +6,13 @@
<%= budget.current_phase.name %>
- <%= investments_count %>
+ <%= investments.count %>
|
- <%= link_to t("valuation.budgets.index.evaluate"),
- valuation_budget_budget_investments_path(budget_id: budget.id),
- class: "button hollow expanded" %>
+ <% if investments.any? %>
+ <%= link_to t("valuation.budgets.index.evaluate"),
+ valuation_budget_budget_investments_path(budget_id: budget.id),
+ class: "button hollow expanded" %>
+ <% end %>
|
diff --git a/app/components/valuation/budgets/row_component.rb b/app/components/valuation/budgets/row_component.rb
index feac0f4c2..4b75b196e 100644
--- a/app/components/valuation/budgets/row_component.rb
+++ b/app/components/valuation/budgets/row_component.rb
@@ -8,9 +8,9 @@ class Valuation::Budgets::RowComponent < ApplicationComponent
@budget = budget
end
- def investments_count
- return 0 unless budget.valuating?
+ def investments
+ return Budget::Investment.none unless budget.valuating?
- budget.investments.visible_to_valuators.by_valuator(current_user.valuator).valuation_open.count
+ budget.investments.visible_to_valuators.by_valuator(current_user.valuator).valuation_open
end
end
diff --git a/spec/components/valuation/budgets/row_component_spec.rb b/spec/components/valuation/budgets/row_component_spec.rb
index 51a3f7671..4d0f1a7af 100644
--- a/spec/components/valuation/budgets/row_component_spec.rb
+++ b/spec/components/valuation/budgets/row_component_spec.rb
@@ -24,4 +24,27 @@ describe Valuation::Budgets::RowComponent do
expect(page).to have_selector(".investments-count", text: "0")
end
+
+ it "Displays the link to evaluate investments when valuator has visible investments assigned and budget is
+ in valuating phase" do
+ valuating = create(:budget, :valuating)
+ create(:budget_investment, :visible_to_valuators, budget: valuating, valuators: [valuator])
+ valuating_invisible = create(:budget, :valuating)
+ create(:budget_investment, :invisible_to_valuators, budget: valuating_invisible, valuators: [valuator])
+ valuating_unassigned = create(:budget, :valuating)
+ create(:budget_investment, :visible_to_valuators, budget: valuating_unassigned)
+ accepting = create(:budget, :accepting)
+ create(:budget_investment, :visible_to_valuators, budget: accepting, valuators: [valuator])
+ finished = create(:budget, :finished)
+ create(:budget_investment, :visible_to_valuators, budget: finished, valuators: [valuator])
+ budgets = [valuating, valuating_invisible, valuating_unassigned, accepting, finished]
+
+ render_inline Valuation::Budgets::RowComponent.with_collection(budgets)
+
+ expect(page.find("#budget_#{valuating.id}")).to have_link("Evaluate")
+ expect(page.find("#budget_#{valuating_invisible.id}")).not_to have_link("Evaluate")
+ expect(page.find("#budget_#{valuating_unassigned.id}")).not_to have_link("Evaluate")
+ expect(page.find("#budget_#{accepting.id}")).not_to have_link("Evaluate")
+ expect(page.find("#budget_#{finished.id}")).not_to have_link("Evaluate")
+ end
end
diff --git a/spec/system/admin/budget_investments_spec.rb b/spec/system/admin/budget_investments_spec.rb
index c0de69ff7..affd87411 100644
--- a/spec/system/admin/budget_investments_spec.rb
+++ b/spec/system/admin/budget_investments_spec.rb
@@ -1567,6 +1567,7 @@ describe "Admin budget investments", :admin do
end
scenario "Shows the correct investments to valuators" do
+ budget.update!(phase: :valuating)
investment1.update!(visible_to_valuators: true)
investment2.update!(visible_to_valuators: false)