diff options
author | Heinrich Lee Yu <hleeyu@gmail.com> | 2018-11-15 09:56:51 +0300 |
---|---|---|
committer | Heinrich Lee Yu <hleeyu@gmail.com> | 2018-12-31 06:00:29 +0300 |
commit | 12e01daec9f24fda742103f9e6c795c358693de5 (patch) | |
tree | 74eda7709f2803585f34cd8d969aefe69feaa782 /spec/models/milestone_spec.rb | |
parent | c07bf1abf2a5c3751e575ee5926e9a052fa0b341 (diff) |
Add group milestones in upcoming filter
Diffstat (limited to 'spec/models/milestone_spec.rb')
-rw-r--r-- | spec/models/milestone_spec.rb | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index b3d31e65c85..23f9f054673 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -240,7 +240,22 @@ describe Milestone do end end - describe '.upcoming_ids_by_projects' do + describe '.upcoming_ids' do + let(:group_1) { create(:group) } + let(:group_2) { create(:group) } + 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_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_3) { create(:milestone, group: group_3, due_date: Time.now - 1.day) } + let(:project_1) { create(:project) } let(:project_2) { create(:project) } let(:project_3) { create(:project) } @@ -258,14 +273,20 @@ describe Milestone do # The call to `#try` is because this returns a relation with a Postgres DB, # and an array of IDs with a MySQL DB. - let(:milestone_ids) { described_class.upcoming_ids_by_projects(projects).map { |id| id.try(:id) || id } } - - it 'returns the next upcoming open milestone ID for each project' do - expect(milestone_ids).to contain_exactly(current_milestone_project_1.id, current_milestone_project_2.id) + let(:milestone_ids) { described_class.upcoming_ids(projects, groups).map { |id| id.try(:id) || id } } + + it 'returns the next upcoming open milestone ID for each project and group' do + expect(milestone_ids).to contain_exactly( + current_milestone_project_1.id, + current_milestone_project_2.id, + current_milestone_group_1.id, + current_milestone_group_2.id + ) end - context 'when the projects have no open upcoming milestones' do + context 'when the projects and groups have no open upcoming milestones' do let(:projects) { [project_3] } + let(:groups) { [group_3] } it 'returns no results' do expect(milestone_ids).to be_empty |