Use Budget::Investment#winners scope to fetch only winner investments

This commit is contained in:
Angel Perez
2018-07-11 12:41:48 -04:00
committed by Javi Martín
parent 62b99f01bc
commit 749954267d
2 changed files with 5 additions and 7 deletions

View File

@@ -3,15 +3,13 @@ module BudgetExecutionsHelper
def winner_investments(heading)
if params[:status].present?
heading.investments
.selected
.sort_by_ballots
.winners
.joins(:milestones)
.distinct
.where('budget_investment_milestones.status_id = ?', params[:status])
else
heading.investments
.selected
.sort_by_ballots
.winners
.joins(:milestones)
.distinct
end

View File

@@ -6,10 +6,10 @@ feature 'Executions' do
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group, price: 1000) }
let!(:investment1) { create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) }
let!(:investment2) { create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) }
let!(:investment1) { create(:budget_investment, :winner, heading: heading, price: 200, ballot_lines_count: 900) }
let!(:investment2) { create(:budget_investment, :winner, heading: heading, price: 300, ballot_lines_count: 800) }
let!(:investment3) { create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) }
let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 600, ballot_lines_count: 600) }
let!(:investment4) { create(:budget_investment, :winner, heading: heading, price: 600, ballot_lines_count: 600) }
scenario 'only displays investments with milestones' do
create(:budget_investment_milestone, investment: investment1)