From fd95c2816d9d84b3907a04b3c88931a7befa2d48 Mon Sep 17 00:00:00 2001 From: jamesspeake Date: Tue, 24 Oct 2023 11:13:03 +0100 Subject: [PATCH] [TAN-423] blank end_at fix for idea.rb --- back/app/models/idea.rb | 2 +- back/spec/models/idea_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/back/app/models/idea.rb b/back/app/models/idea.rb index fc8c8cb4adc4..a6ea9de0ac55 100644 --- a/back/app/models/idea.rb +++ b/back/app/models/idea.rb @@ -183,7 +183,7 @@ def input_term else now = Time.zone.now phases_with_ideas = phases.select(&:can_contain_ideas?).sort_by(&:start_at) - first_past_phase_with_ideas = phases_with_ideas.reverse_each.detect { |phase| phase.end_at <= now } + first_past_phase_with_ideas = phases_with_ideas.reverse_each.detect { |phase| phase.end_at&.<= now } if first_past_phase_with_ideas first_past_phase_with_ideas.input_term else # now is before the first phase with ideas diff --git a/back/spec/models/idea_spec.rb b/back/spec/models/idea_spec.rb index c714cead9b19..ee0b87487529 100644 --- a/back/spec/models/idea_spec.rb +++ b/back/spec/models/idea_spec.rb @@ -185,6 +185,28 @@ end end + context 'when the current ideation phase has no end date' do + let(:project) { create(:project_with_two_past_ideation_phases) } + let(:phase) { project.phases.last } + let(:idea) { build(:idea, project: project, phases: project.phases) } + + it 'returns the input_term of the open ended (current) ideation phase' do + phase.update!(input_term: 'issue') + expect(idea.input_term).to eq 'issue' + end + end + + context 'when a future ideation phase has no end date' do + let(:project) { create(:project_with_past_ideation_and_future_ideation_phase) } + let(:idea) { build(:idea, project: project, phases: project.phases) } + + it 'returns the input_term of the past ideation phase' do + project.phases.last.update!(end_at: nil, input_term: 'option') + project.phases.first.update!(input_term: 'issue') + expect(idea.input_term).to eq 'issue' + end + end + context 'when there is no active ideation or budgeting phase' do context 'when the idea does not belong to any phase' do # The project and the phase are given an input_term to describe that they