From 5856af03a5b70831cedec3caaf018aaa5b5b486a Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Mon, 10 Sep 2018 18:36:04 +0200 Subject: [PATCH] Fix exception when no available milestones We were getting an exception when quering[1] for milestones which were not present, due to for example having a publication date later than today Adding a `try` statement and spec to avoid this situation [1] https://github.com/AyuntamientoMadrid/consul/blob/82efc3dd661675dad753eaa0c485fab5d27a7d9f/app/controllers/budgets/executions_controller.rb#L16 --- app/controllers/budgets/executions_controller.rb | 2 +- spec/features/budgets/executions_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/budgets/executions_controller.rb b/app/controllers/budgets/executions_controller.rb index e33f43dcd..b321c4377 100644 --- a/app/controllers/budgets/executions_controller.rb +++ b/app/controllers/budgets/executions_controller.rb @@ -13,7 +13,7 @@ module Budgets .joins(:milestones).includes(:milestones) .select { |i| i.milestones.published.with_status .order_by_publication_date.last - .status_id == params[:status].to_i } + .try(:status_id) == params[:status].to_i } .uniq .group_by(&:heading) else diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 5449c8c4b..56e030ec7 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -249,4 +249,18 @@ feature 'Executions' do expect(m_heading.name).to appear_before(z_heading.name) end end + + context 'No milestones' do + + scenario 'Milestone not yet published' do + status = create(:budget_investment_status) + unpublished_milestone = create(:budget_investment_milestone, investment: investment1, + status: status, publication_date: Date.tomorrow) + + visit custom_budget_executions_path(budget, status: status.id) + + expect(page).to have_content('No winner investments in this state') + end + + end end