Add headings_voted_by_user

This method was used only in Madrid’s fork, but it is now needed to
complete the backport for voting in multiple headings

There wasn’t a test in Madrid, so here goes one too. Even though, the
responsibility should probably be moved soon to the `Budget::Heading`.
For consistency with the related methods and tests it has been left in
the investment_spec
This commit is contained in:
rgarcia
2018-03-22 22:24:38 +01:00
parent 0398bb23cb
commit 5c6eaa76ff
2 changed files with 33 additions and 0 deletions

View File

@@ -239,6 +239,10 @@ class Budget
headings_voted_by_user(user).count < group.max_votable_headings
end
def headings_voted_by_user(user)
user.votes.for_budget_investments(budget.investments.where(group: group)).votables.map(&:heading_id).uniq
end
def voted_in?(heading_ids, user)
heading_ids.include? heading_voted_by_user?(user)
end