Count only the investments visible and assigned to current valuator

It has more sense to show the count of the investments the
valuator is going to find in the investments valuation page.
This commit is contained in:
Senén Rodero Rodríguez
2023-01-13 13:04:53 +01:00
parent 282b8f8697
commit 615b249144
4 changed files with 32 additions and 6 deletions

View File

@@ -5,7 +5,7 @@
<td>
<%= budget.current_phase.name %>
</td>
<td>
<td class="investments-count">
<%= investments_count %>
</td>
<td>

View File

@@ -9,6 +9,8 @@ class Valuation::Budgets::RowComponent < ApplicationComponent
end
def investments_count
budget.investments.by_valuator(current_user.valuator).valuation_open.count
return 0 unless budget.valuating?
budget.investments.visible_to_valuators.by_valuator(current_user.valuator).valuation_open.count
end
end

View File

@@ -0,0 +1,27 @@
require "rails_helper"
describe Valuation::Budgets::RowComponent do
let(:valuator) { create(:valuator) }
before { sign_in(valuator.user) }
it "Displays visible and assigned investments count when budget is in valuating phase" do
budget = create(:budget, :valuating, name: "Sports")
create(:budget_investment, :visible_to_valuators, budget: budget, valuators: [valuator])
create(:budget_investment, :invisible_to_valuators, budget: budget, valuators: [valuator])
create(:budget_investment, :visible_to_valuators, budget: budget)
render_inline Valuation::Budgets::RowComponent.new(budget: budget)
expect(page).to have_selector(".investments-count", text: "1")
end
it "Displays zero as investments count when budget is not in valuating phase" do
budget = create(:budget, %i[accepting finished].sample, name: "Sports")
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
end

View File

@@ -1,10 +1,7 @@
require "rails_helper"
describe "Valuation budgets" do
before do
valuator = create(:valuator, user: create(:user, username: "Rachel", email: "rachel@valuators.org"))
login_as(valuator.user)
end
before { login_as(create(:valuator).user) }
context "Index" do
scenario "Displays published budgets" do