Skip to content

Commit

Permalink
[TAN-423] blank end_at fix for idea.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesspeake committed Oct 24, 2023
1 parent ad7d452 commit fd95c28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion back/app/models/idea.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions back/spec/models/idea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd95c28

Please sign in to comment.