Do not show the Evaluate link when there are no projects to evaluate for current valuator

This commit is contained in:
Senén Rodero Rodríguez
2023-01-13 13:51:32 +01:00
parent 615b249144
commit 0c09fd22af
4 changed files with 33 additions and 7 deletions

View File

@@ -6,11 +6,13 @@
<%= budget.current_phase.name %>
</td>
<td class="investments-count">
<%= investments_count %>
<%= investments.count %>
</td>
<td>
<%= 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 %>
</td>
</tr>

View File

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

View File

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

View File

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