diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 01:45:44 +0000 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /spec/models/iteration_spec.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) | |
download | gitlab-ce-85dc423f7090da0a52c73eb66faf22ddb20efff9.tar.gz |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'spec/models/iteration_spec.rb')
-rw-r--r-- | spec/models/iteration_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/iteration_spec.rb b/spec/models/iteration_spec.rb index 5c684fa9771..19a1625aad3 100644 --- a/spec/models/iteration_spec.rb +++ b/spec/models/iteration_spec.rb @@ -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) } |