diff options
author | George Andrinopoulos <geoandri@gmail.com> | 2017-10-29 23:58:49 +0300 |
---|---|---|
committer | George Andrinopoulos <geoandri@gmail.com> | 2017-11-11 17:47:39 +0300 |
commit | f39fe4d8db2d7fc6443c68aefff60f3eafcdf602 (patch) | |
tree | 632b6308200d934dab60d3c812473207bd3067f2 /spec/models | |
parent | d180affa210bd6e5474746bcfed006cee9d3730e (diff) |
Add total time spent to milestones
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/global_milestone_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/milestone_spec.rb | 23 |
2 files changed, 56 insertions, 0 deletions
diff --git a/spec/models/global_milestone_spec.rb b/spec/models/global_milestone_spec.rb index ab58f5c5021..4874dcbd58e 100644 --- a/spec/models/global_milestone_spec.rb +++ b/spec/models/global_milestone_spec.rb @@ -190,4 +190,37 @@ describe GlobalMilestone do end end end + + describe '#total_time_spent' do + let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) } + let(:milestone1_project2) { create(:milestone, title: "Milestone v1.2", project: project2) } + let(:issue1) { create(:issue, milestone: milestone1_project1) } + let(:issue2) { create(:issue, milestone: milestone1_project2) } + let(:merge_request1) { create(:merge_request, milestone: milestone1_project1) } + let(:merge_request2) { create(:merge_request, milestone: milestone1_project2) } + + before do + milestones = + [ + milestone1_project1, + milestone1_project2 + ] + milestones_relation = Milestone.where(id: milestones.map(&:id)) + + @global_milestone = described_class.new(milestone1_project1.title, milestones_relation) + end + + it 'calculates total time spent' do + issue1.spend_time(duration: 300, user: user) + issue1.save! + issue2.spend_time(duration: 600, user: user2) + issue2.save! + merge_request1.spend_time(duration: 200, user: user) + merge_request1.save! + merge_request2.spend_time(duration: 100, user: user2) + merge_request2.save! + + expect(@global_milestone.total_time_spent).to eq(1200) + end + end end diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 13e37fffa4e..10c24317574 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -284,4 +284,27 @@ describe Milestone do expect(milestone.participants).to eq [user] end end + + describe '#total_time_spent' do + let(:user) { build(:user) } + let(:project) { build(:project, name: 'sample-project') } + let(:milestone) { build(:milestone, iid: 1, project: project) } + let(:issue1) { build(:issue, milestone: milestone) } + let(:issue2) { build(:issue, milestone: milestone) } + let(:merge_request1) { build(:merge_request, milestone: milestone) } + let(:merge_request2) { build(:merge_request, milestone: milestone) } + + it 'calculates total time spent' do + issue1.spend_time(duration: 300, user: user) + issue1.save! + issue2.spend_time(duration: 600, user: user) + issue2.save! + merge_request1.spend_time(duration: 200, user: user) + merge_request1.save! + merge_request2.spend_time(duration: 100, user: user) + merge_request2.save! + + expect(milestone.total_time_spent).to eq(1200) + end + end end |