Commit 38ad15a5 authored by Mario de la Ossa's avatar Mario de la Ossa

Fix iterations quickaction to show opened iterations

Due to a missed spot when we refactored Iteration states, the Iteration
quickaction was not finding any iterations because it was being sent an
invalid 'state'.
parent 1f00f6e6
......@@ -29,6 +29,7 @@ class Iteration < ApplicationRecord
scope :upcoming, -> { with_state(:upcoming) }
scope :started, -> { with_state(:started) }
scope :closed, -> { with_state(:closed) }
scope :within_timeframe, -> (start_date, end_date) do
where('start_date is not NULL or due_date is not NULL')
......@@ -63,9 +64,10 @@ class Iteration < ApplicationRecord
case state
when 'closed' then iterations.closed
when 'started' then iterations.started
when 'upcoming' then iterations.upcoming
when 'opened' then iterations.started.or(iterations.upcoming)
when 'all' then iterations
else iterations.upcoming
else raise ArgumentError, "Unknown state filter: #{state}"
end
end
......
---
title: Fix Iterations quickaction not showing all iterations
merge_request: 42528
author:
type: fixed
......@@ -99,11 +99,11 @@ module EE
quick_action_target.supports_iterations? &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project) &&
quick_action_target.project.group&.feature_available?(:iterations) &&
find_iterations(project, state: 'active').any?
find_iterations(project, state: 'opened').any?
end
parse_params do |iteration_param|
extract_references(iteration_param, :iteration).first ||
find_iterations(project, title: iteration_param.strip).first
find_iterations(project, title: iteration_param.strip, state: 'opened').first
end
command :iteration do |iteration|
@updates[:iteration] = iteration if iteration
......
......@@ -232,6 +232,19 @@ RSpec.describe QuickActions::InterpretService do
expect(updates).to eq(iteration: iteration)
expect(message).to eq("Set the iteration to #{iteration.to_reference}.")
end
context 'when iteration is started' do
before do
iteration.start!
end
it 'assigns an iteration to an issue' do
_, updates, message = service.execute(content, issue)
expect(updates).to eq(iteration: iteration)
expect(message).to eq("Set the iteration to #{iteration.to_reference}.")
end
end
end
context 'when the user does not have enough permissions' do
......
......@@ -32,6 +32,59 @@ RSpec.describe Iteration do
end
end
describe '.filter_by_state' do
let_it_be(:closed_iteration) { create(:iteration, :closed, :skip_future_date_validation, group: group, start_date: 8.days.ago, due_date: 2.days.ago) }
let_it_be(:started_iteration) { create(:iteration, :started, :skip_future_date_validation, group: group, start_date: 1.day.ago, due_date: 6.days.from_now) }
let_it_be(:upcoming_iteration) { create(:iteration, :upcoming, group: group, start_date: 1.week.from_now, due_date: 2.weeks.from_now) }
shared_examples_for 'filter_by_state' do
it 'filters by the given state' do
expect(described_class.filter_by_state(Iteration.all, state)).to match(expected_iterations)
end
end
context 'filtering by closed iterations' do
it_behaves_like 'filter_by_state' do
let(:state) { 'closed' }
let(:expected_iterations) { [closed_iteration] }
end
end
context 'filtering by started iterations' do
it_behaves_like 'filter_by_state' do
let(:state) { 'started' }
let(:expected_iterations) { [started_iteration] }
end
end
context 'filtering by opened iterations' do
it_behaves_like 'filter_by_state' do
let(:state) { 'opened' }
let(:expected_iterations) { [started_iteration, upcoming_iteration] }
end
end
context 'filtering by upcoming iterations' do
it_behaves_like 'filter_by_state' do
let(:state) { 'upcoming' }
let(:expected_iterations) { [upcoming_iteration] }
end
end
context 'filtering by "all"' do
it_behaves_like 'filter_by_state' do
let(:state) { 'all' }
let(:expected_iterations) { [closed_iteration, started_iteration, upcoming_iteration] }
end
end
context 'filtering by nonexistent filter' do
it 'raises ArgumentError' do
expect { described_class.filter_by_state(Iteration.none, 'unknown') }.to raise_error(ArgumentError, 'Unknown state filter: unknown')
end
end
end
context 'Validations' do
subject { build(:iteration, group: group, start_date: start_date, due_date: due_date) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment