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>
25 lines
560 B
Ruby
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
|