Show link to evaluate after evaluation has finished

This way it's still possible to access the "evaluation finished" filter
in the valuation investments index.
This commit is contained in:
Javi Martín
2023-02-04 16:05:28 +01:00
parent d5cb01bf98
commit ed4b03c3ed
3 changed files with 46 additions and 7 deletions

View File

@@ -6,7 +6,7 @@
<%= budget.current_phase.name %> <%= budget.current_phase.name %>
</td> </td>
<td class="investments-count"> <td class="investments-count">
<%= investments.count %> <%= valuation_open_investments_count %>
</td> </td>
<td> <td>
<% if investments.any? %> <% if investments.any? %>

View File

@@ -9,8 +9,14 @@ class Valuation::Budgets::RowComponent < ApplicationComponent
end end
def investments def investments
return Budget::Investment.none unless budget.valuating? return Budget::Investment.none unless budget.valuating_or_later?
budget.investments.visible_to_valuators.by_valuator(current_user.valuator).valuation_open budget.investments.visible_to_valuators.by_valuator(current_user.valuator)
end
def valuation_open_investments_count
return 0 unless budget.valuating?
investments.valuation_open.count
end end
end end

View File

@@ -17,8 +17,29 @@ describe Valuation::Budgets::RowComponent do
expect(page).to have_selector ".investments-count", text: "1" expect(page).to have_selector ".investments-count", text: "1"
end end
it "displays zero when the budget is not in the valuating phase" do it "does not count investments with valuation finished" do
budget = create(:budget, %i[accepting finished].sample) budget = create(:budget, :valuating)
create(:budget_investment, :visible_to_valuators,
budget: budget,
valuators: [valuator],
valuation_finished: true)
render_inline Valuation::Budgets::RowComponent.new(budget: budget)
expect(page).to have_selector ".investments-count", text: "0"
end
it "displays zero when the budget hasn't reached the valuating phase" do
budget = create(:budget, :accepting)
create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])
render_inline Valuation::Budgets::RowComponent.new(budget: budget)
expect(page).to have_selector ".investments-count", text: "0"
end
it "displays zero when the valuating phase is over" do
budget = create(:budget, :finished)
create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator]) create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])
render_inline Valuation::Budgets::RowComponent.new(budget: budget) render_inline Valuation::Budgets::RowComponent.new(budget: budget)
@@ -37,6 +58,18 @@ describe Valuation::Budgets::RowComponent do
expect(page).to have_link "Evaluate" expect(page).to have_link "Evaluate"
end end
it "is shown when the assigned investments have finished valuation" do
budget = create(:budget, :valuating)
create(:budget_investment, :visible_to_valuators,
budget: budget,
valuators: [valuator],
valuation_finished: true)
render_inline Valuation::Budgets::RowComponent.new(budget: budget)
expect(page).to have_link "Evaluate"
end
it "is not shown when the assigned investments aren't visible to valuators" do it "is not shown when the assigned investments aren't visible to valuators" do
budget = create(:budget, :valuating) budget = create(:budget, :valuating)
create(:budget_investment, :invisible_to_valuators, budget: budget, valuators: [valuator]) create(:budget_investment, :invisible_to_valuators, budget: budget, valuators: [valuator])
@@ -64,13 +97,13 @@ describe Valuation::Budgets::RowComponent do
expect(page).not_to have_link "Evaluate" expect(page).not_to have_link "Evaluate"
end end
it "is not shown when the valuating phase is over" do it "is shown when the valuating phase is over" do
budget = create(:budget, :finished) budget = create(:budget, :finished)
create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator]) create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])
render_inline Valuation::Budgets::RowComponent.new(budget: budget) render_inline Valuation::Budgets::RowComponent.new(budget: budget)
expect(page).not_to have_link "Evaluate" expect(page).to have_link "Evaluate"
end end
end end
end end