diff options
author | Eagllus <rvanzon@gitlab.com> | 2018-10-16 15:18:25 +0200 |
---|---|---|
committer | Eagllus <rvanzon@gitlab.com> | 2018-10-17 15:42:10 +0200 |
commit | d96585f5739f4cb83fd00fa402192a15d6958881 (patch) | |
tree | 1c3cf954991fd0927a613ca0076a0d38ac439044 /spec | |
parent | 074fafe9e09935cd53cf286ad00b9d53240a9413 (diff) | |
download | gitlab-ce-d96585f5739f4cb83fd00fa402192a15d6958881.tar.gz |
Moving state_count to Milestone model and related tests
By moving and improving state_count the functions in GlobalMilestone
are no longer used.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/models/global_milestone_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/milestone_spec.rb | 35 |
2 files changed, 35 insertions, 35 deletions
diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb index ab58f5c5021..b6355455c1d 100644 --- a/spec/models/global_milestone_spec.rb +++ b/spec/models/global_milestone_spec.rb @@ -92,41 +92,6 @@ describe GlobalMilestone do end end - describe '.states_count' do - context 'when the projects have milestones' do - before do - create(:closed_milestone, title: 'Active Group Milestone', project: project3) - create(:active_milestone, title: 'Active Group Milestone', project: project1) - create(:active_milestone, title: 'Active Group Milestone', project: project2) - create(:closed_milestone, title: 'Closed Group Milestone', project: project1) - create(:closed_milestone, title: 'Closed Group Milestone', project: project2) - create(:closed_milestone, title: 'Closed Group Milestone', project: project3) - end - - it 'returns the quantity of global milestones in each possible state' do - expected_count = { opened: 1, closed: 2, all: 2 } - - count = described_class.states_count(Project.all) - - expect(count).to eq(expected_count) - end - end - - context 'when the projects do not have milestones' do - before do - project1 - end - - it 'returns 0 as the quantity of global milestones in each state' do - expected_count = { opened: 0, closed: 0, all: 0 } - - count = described_class.states_count(Project.all) - - expect(count).to eq(expected_count) - end - end - end - describe '#initialize' do let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) } let(:milestone1_project2) { create(:milestone, title: "Milestone v1.2", project: project2) } diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 27d4e622710..b6aad769e3b 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -348,4 +348,39 @@ describe Milestone do end end end + + describe '.states_count' do + context 'when the projects have milestones' do + let(:project_1) { create(:project) } + let(:project_2) { create(:project) } + let(:project_3) { create(:project) } + + before do + create(:closed_milestone, title: 'Active Group Milestone', project: project_3) + create(:active_milestone, title: 'Active Group Milestone', project: project_1) + create(:active_milestone, title: 'Active Group Milestone', project: project_2) + create(:closed_milestone, title: 'Closed Group Milestone', project: project_1) + create(:closed_milestone, title: 'Closed Group Milestone', project: project_2) + create(:closed_milestone, title: 'Closed Group Milestone', project: project_3) + end + + it 'returns the quantity of milestones in each possible state' do + expected_count = { opened: 5, closed: 4, all: 9 } + + count = described_class.states_count(Project.all) + + expect(count).to eq(expected_count) + end + end + + context 'when the projects do not have milestones' do + it 'returns 0 as the quantity of global milestones in each state' do + expected_count = { opened: 0, closed: 0, all: 0 } + + count = described_class.states_count([project]) + + expect(count).to eq(expected_count) + end + end + end end |