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:
@@ -5,7 +5,7 @@
|
||||
<td>
|
||||
<%= budget.current_phase.name %>
|
||||
</td>
|
||||
<td>
|
||||
<td class="investments-count">
|
||||
<%= investments_count %>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -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
|
||||
|
||||
27
spec/components/valuation/budgets/row_component_spec.rb
Normal file
27
spec/components/valuation/budgets/row_component_spec.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user