diff --git a/app/helpers/budget_executions_helper.rb b/app/helpers/budget_executions_helper.rb index ec448c675..64caa0c18 100644 --- a/app/helpers/budget_executions_helper.rb +++ b/app/helpers/budget_executions_helper.rb @@ -6,7 +6,7 @@ module BudgetExecutionsHelper .winners .joins(:milestones) .distinct - .where('budget_investment_milestones.status_id = ?', params[:status]) + .where(filter_investment_by_latest_milestone, params[:status]) else heading.investments .winners @@ -15,4 +15,11 @@ module BudgetExecutionsHelper end end + def filter_investment_by_latest_milestone + <<-SQL + (SELECT status_id FROM budget_investment_milestones + WHERE investment_id = budget_investments.id ORDER BY publication_date DESC LIMIT 1) = ? + SQL + end + end diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 03bdc21ab..0f8a31a8d 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -138,7 +138,7 @@ feature 'Executions' do expect(page).not_to have_content(investment2.title) end - xscenario 'are based on latest milestone status', :js do + scenario 'are based on latest milestone status', :js do create(:budget_investment_milestone, investment: investment1, publication_date: Date.yesterday, status: status1) @@ -157,10 +157,12 @@ feature 'Executions' do select 'Studying the project', from: 'status' expect(page).not_to have_content(investment1.title) + expect(page).to have_content('No winner investments for this heading') select 'Bidding', from: 'status' expect(page).to have_content(investment1.title) + expect(page).not_to have_content('No winner investments for this heading') end end