diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/models/milestone_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/models/milestone_spec.rb')
-rw-r--r-- | spec/models/milestone_spec.rb | 155 |
1 files changed, 96 insertions, 59 deletions
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index e51108947a7..33f84da27f6 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -81,7 +81,7 @@ describe Milestone do end it_behaves_like 'within_timeframe scope' do - let_it_be(:now) { Time.now } + let_it_be(:now) { Time.current } let_it_be(:project) { create(:project, :empty_repo) } let_it_be(:resource_1) { create(:milestone, project: project, start_date: now - 1.day, due_date: now + 1.day) } let_it_be(:resource_2) { create(:milestone, project: project, start_date: now + 2.days, due_date: now + 3.days) } @@ -130,7 +130,7 @@ describe Milestone do describe '#upcoming?' do it 'returns true when start_date is in the future' do - milestone = build(:milestone, start_date: Time.now + 1.month) + milestone = build(:milestone, start_date: Time.current + 1.month) expect(milestone.upcoming?).to be_truthy end @@ -225,70 +225,88 @@ describe Milestone do end end - describe '#for_projects_and_groups' do - let(:project) { create(:project) } - let(:project_other) { create(:project) } - let(:group) { create(:group) } - let(:group_other) { create(:group) } + shared_examples '#for_projects_and_groups' do + describe '#for_projects_and_groups' do + let_it_be(:project) { create(:project) } + let_it_be(:project_other) { create(:project) } + let_it_be(:group) { create(:group) } + let_it_be(:group_other) { create(:group) } + + before(:all) do + create(:milestone, project: project) + create(:milestone, project: project_other) + create(:milestone, group: group) + create(:milestone, group: group_other) + end - before do - create(:milestone, project: project) - create(:milestone, project: project_other) - create(:milestone, group: group) - create(:milestone, group: group_other) - end + subject { described_class.for_projects_and_groups(projects, groups) } + + shared_examples 'filters by projects and groups' do + it 'returns milestones filtered by project' do + milestones = described_class.for_projects_and_groups(projects, []) - subject { described_class.for_projects_and_groups(projects, groups) } + expect(milestones.count).to eq(1) + expect(milestones.first.project_id).to eq(project.id) + end + + it 'returns milestones filtered by group' do + milestones = described_class.for_projects_and_groups([], groups) + + expect(milestones.count).to eq(1) + expect(milestones.first.group_id).to eq(group.id) + end - shared_examples 'filters by projects and groups' do - it 'returns milestones filtered by project' do - milestones = described_class.for_projects_and_groups(projects, []) + it 'returns milestones filtered by both project and group' do + milestones = described_class.for_projects_and_groups(projects, groups) - expect(milestones.count).to eq(1) - expect(milestones.first.project_id).to eq(project.id) + expect(milestones.count).to eq(2) + expect(milestones).to contain_exactly(project.milestones.first, group.milestones.first) + end end - it 'returns milestones filtered by group' do - milestones = described_class.for_projects_and_groups([], groups) + context 'ids as params' do + let(:projects) { [project.id] } + let(:groups) { [group.id] } - expect(milestones.count).to eq(1) - expect(milestones.first.group_id).to eq(group.id) + it_behaves_like 'filters by projects and groups' end - it 'returns milestones filtered by both project and group' do - milestones = described_class.for_projects_and_groups(projects, groups) + context 'relations as params' do + let(:projects) { Project.where(id: project.id).select(:id) } + let(:groups) { Group.where(id: group.id).select(:id) } - expect(milestones.count).to eq(2) - expect(milestones).to contain_exactly(project.milestones.first, group.milestones.first) + it_behaves_like 'filters by projects and groups' end - end - context 'ids as params' do - let(:projects) { [project.id] } - let(:groups) { [group.id] } + context 'objects as params' do + let(:projects) { [project] } + let(:groups) { [group] } - it_behaves_like 'filters by projects and groups' - end + it_behaves_like 'filters by projects and groups' + end - context 'relations as params' do - let(:projects) { Project.where(id: project.id).select(:id) } - let(:groups) { Group.where(id: group.id).select(:id) } + it 'returns no records if projects and groups are nil' do + milestones = described_class.for_projects_and_groups(nil, nil) - it_behaves_like 'filters by projects and groups' + expect(milestones).to be_empty + end end + end - context 'objects as params' do - let(:projects) { [project] } - let(:groups) { [group] } - - it_behaves_like 'filters by projects and groups' + context 'when `optimized_timebox_queries` feature flag is enabled' do + before do + stub_feature_flags(optimized_timebox_queries: true) end - it 'returns no records if projects and groups are nil' do - milestones = described_class.for_projects_and_groups(nil, nil) + it_behaves_like '#for_projects_and_groups' + end - expect(milestones).to be_empty + context 'when `optimized_timebox_queries` feature flag is disabled' do + before do + stub_feature_flags(optimized_timebox_queries: false) end + + it_behaves_like '#for_projects_and_groups' end describe '.upcoming_ids' do @@ -297,30 +315,30 @@ describe Milestone do let(:group_3) { create(:group) } let(:groups) { [group_1, group_2, group_3] } - let!(:past_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.now - 1.day) } - let!(:current_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.now + 1.day) } - let!(:future_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.now + 2.days) } + let!(:past_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.current - 1.day) } + let!(:current_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.current + 1.day) } + let!(:future_milestone_group_1) { create(:milestone, group: group_1, due_date: Time.current + 2.days) } - let!(:past_milestone_group_2) { create(:milestone, group: group_2, due_date: Time.now - 1.day) } - let!(:closed_milestone_group_2) { create(:milestone, :closed, group: group_2, due_date: Time.now + 1.day) } - let!(:current_milestone_group_2) { create(:milestone, group: group_2, due_date: Time.now + 2.days) } + let!(:past_milestone_group_2) { create(:milestone, group: group_2, due_date: Time.current - 1.day) } + let!(:closed_milestone_group_2) { create(:milestone, :closed, group: group_2, due_date: Time.current + 1.day) } + let!(:current_milestone_group_2) { create(:milestone, group: group_2, due_date: Time.current + 2.days) } - let!(:past_milestone_group_3) { create(:milestone, group: group_3, due_date: Time.now - 1.day) } + let!(:past_milestone_group_3) { create(:milestone, group: group_3, due_date: Time.current - 1.day) } let(:project_1) { create(:project) } let(:project_2) { create(:project) } let(:project_3) { create(:project) } let(:projects) { [project_1, project_2, project_3] } - let!(:past_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.now - 1.day) } - let!(:current_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.now + 1.day) } - let!(:future_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.now + 2.days) } + let!(:past_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.current - 1.day) } + let!(:current_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.current + 1.day) } + let!(:future_milestone_project_1) { create(:milestone, project: project_1, due_date: Time.current + 2.days) } - let!(:past_milestone_project_2) { create(:milestone, project: project_2, due_date: Time.now - 1.day) } - let!(:closed_milestone_project_2) { create(:milestone, :closed, project: project_2, due_date: Time.now + 1.day) } - let!(:current_milestone_project_2) { create(:milestone, project: project_2, due_date: Time.now + 2.days) } + let!(:past_milestone_project_2) { create(:milestone, project: project_2, due_date: Time.current - 1.day) } + let!(:closed_milestone_project_2) { create(:milestone, :closed, project: project_2, due_date: Time.current + 1.day) } + let!(:current_milestone_project_2) { create(:milestone, project: project_2, due_date: Time.current + 2.days) } - let!(:past_milestone_project_3) { create(:milestone, project: project_3, due_date: Time.now - 1.day) } + let!(:past_milestone_project_3) { create(:milestone, project: project_3, due_date: Time.current - 1.day) } let(:milestone_ids) { described_class.upcoming_ids(projects, groups).map(&:id) } @@ -498,4 +516,23 @@ describe Milestone do end end end + + describe '#subgroup_milestone' do + context 'parent is subgroup' do + it 'returns true' do + group = create(:group) + subgroup = create(:group, :private, parent: group) + + expect(build(:milestone, group: subgroup).subgroup_milestone?).to eq(true) + end + end + + context 'parent is not subgroup' do + it 'returns false' do + group = create(:group) + + expect(build(:milestone, group: group).subgroup_milestone?).to eq(false) + end + end + end end |