Files
nairobi/app/components/budgets/investments_list_component.rb
decabeza 122195e33c Show a preview list of investments in the budget landing page
Note one of the tests dealing with random results is a bit flaky; since
it's a permutation selecting 7 objects out of 12, it will fail about
once every 4 million times. We think this is acceptable.

Co-Authored-By: Julian Nicolas Herrero <microweb10@gmail.com>
2021-06-11 19:32:21 +02:00

25 lines
560 B
Ruby

class Budgets::InvestmentsListComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
def render?
budget.single_heading?
end
def investments(limit: 9)
case budget.phase
when "accepting", "reviewing"
budget.investments.sample(limit)
when "selecting", "valuating", "publishing_prices"
budget.investments.feasible.sample(limit)
when "balloting", "reviewing_ballots"
budget.investments.selected.sample(limit)
else
budget.investments.none
end
end
end