From 615b2491449e355e2c652b09ab8aee71ba33f5a9 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:04:53 +0100
Subject: [PATCH] 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.
---
.../valuation/budgets/row_component.html.erb | 2 +-
.../valuation/budgets/row_component.rb | 4 ++-
.../valuation/budgets/row_component_spec.rb | 27 +++++++++++++++++++
spec/system/valuation/budgets_spec.rb | 5 +---
4 files changed, 32 insertions(+), 6 deletions(-)
create mode 100644 spec/components/valuation/budgets/row_component_spec.rb
diff --git a/app/components/valuation/budgets/row_component.html.erb b/app/components/valuation/budgets/row_component.html.erb
index be3fc52c5..7489b50af 100644
--- a/app/components/valuation/budgets/row_component.html.erb
+++ b/app/components/valuation/budgets/row_component.html.erb
@@ -5,7 +5,7 @@
<%= budget.current_phase.name %>
|
-
+ |
<%= investments_count %>
|
diff --git a/app/components/valuation/budgets/row_component.rb b/app/components/valuation/budgets/row_component.rb
index da8e3f107..feac0f4c2 100644
--- a/app/components/valuation/budgets/row_component.rb
+++ b/app/components/valuation/budgets/row_component.rb
@@ -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
diff --git a/spec/components/valuation/budgets/row_component_spec.rb b/spec/components/valuation/budgets/row_component_spec.rb
new file mode 100644
index 000000000..51a3f7671
--- /dev/null
+++ b/spec/components/valuation/budgets/row_component_spec.rb
@@ -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
diff --git a/spec/system/valuation/budgets_spec.rb b/spec/system/valuation/budgets_spec.rb
index 88b6f52e2..4233cd9d1 100644
--- a/spec/system/valuation/budgets_spec.rb
+++ b/spec/system/valuation/budgets_spec.rb
@@ -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
|