Commit 1da8160d authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '248562-iteration-quickaction-bug' into 'master'

Fix iterations quickaction to show opened iterations

See merge request gitlab-org/gitlab!42528
parents 0e8e9ab1 38ad15a5
...@@ -29,6 +29,7 @@ class Iteration < ApplicationRecord ...@@ -29,6 +29,7 @@ class Iteration < ApplicationRecord
scope :upcoming, -> { with_state(:upcoming) } scope :upcoming, -> { with_state(:upcoming) }
scope :started, -> { with_state(:started) } scope :started, -> { with_state(:started) }
scope :closed, -> { with_state(:closed) }
scope :within_timeframe, -> (start_date, end_date) do scope :within_timeframe, -> (start_date, end_date) do
where('start_date is not NULL or due_date is not NULL') where('start_date is not NULL or due_date is not NULL')
...@@ -63,9 +64,10 @@ class Iteration < ApplicationRecord ...@@ -63,9 +64,10 @@ class Iteration < ApplicationRecord
case state case state
when 'closed' then iterations.closed when 'closed' then iterations.closed
when 'started' then iterations.started when 'started' then iterations.started
when 'upcoming' then iterations.upcoming
when 'opened' then iterations.started.or(iterations.upcoming) when 'opened' then iterations.started.or(iterations.upcoming)
when 'all' then iterations when 'all' then iterations
else iterations.upcoming else raise ArgumentError, "Unknown state filter: #{state}"
end end
end end
......
---
title: Fix Iterations quickaction not showing all iterations
merge_request: 42528
author:
type: fixed
...@@ -99,11 +99,11 @@ module EE ...@@ -99,11 +99,11 @@ module EE
quick_action_target.supports_iterations? && quick_action_target.supports_iterations? &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project) && current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project) &&
quick_action_target.project.group&.feature_available?(:iterations) && quick_action_target.project.group&.feature_available?(:iterations) &&
find_iterations(project, state: 'active').any? find_iterations(project, state: 'opened').any?
end end
parse_params do |iteration_param| parse_params do |iteration_param|
extract_references(iteration_param, :iteration).first || 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 end
command :iteration do |iteration| command :iteration do |iteration|
@updates[:iteration] = iteration if iteration @updates[:iteration] = iteration if iteration
......
...@@ -232,6 +232,19 @@ RSpec.describe QuickActions::InterpretService do ...@@ -232,6 +232,19 @@ RSpec.describe QuickActions::InterpretService do
expect(updates).to eq(iteration: iteration) expect(updates).to eq(iteration: iteration)
expect(message).to eq("Set the iteration to #{iteration.to_reference}.") expect(message).to eq("Set the iteration to #{iteration.to_reference}.")
end 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 end
context 'when the user does not have enough permissions' do context 'when the user does not have enough permissions' do
......
...@@ -32,6 +32,59 @@ RSpec.describe Iteration do ...@@ -32,6 +32,59 @@ RSpec.describe Iteration do
end end
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 context 'Validations' do
subject { build(:iteration, group: group, start_date: start_date, due_date: due_date) } 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