Commit 98d6d491 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move global milestone specs

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c79d801b
module Milestones
class CollectionService < Milestones::BaseService
def initialize(project_milestones)
@project_milestones = project_milestones.group_by(&:title)
end
def execute
build(@project_milestones)
end
def milestone(title)
if title
group_milestone = @project_milestones[title].group_by(&:title)
build(group_milestone).first
else
nil
end
end
private
def build(milestone)
milestone.map{ |title, milestones| GroupMilestone.new(title, milestones) }
end
end
end
require 'spec_helper'
describe Milestones::GroupService do
describe GlobalMilestone do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let(:group) { create(:group) }
......@@ -14,57 +14,52 @@ describe Milestones::GroupService do
let(:milestone2_project2) { create(:milestone, title: "VD-123", project: project2) }
let(:milestone2_project3) { create(:milestone, title: "VD-123", project: project3) }
describe 'execute' do
context 'with valid projects' do
before do
milestones =
[
milestone1_project1,
milestone1_project2,
milestone1_project3,
milestone2_project1,
milestone2_project2,
milestone2_project3
]
@group_milestones = Milestones::GroupService.new(milestones).execute
end
describe :build_collection do
before do
milestones =
[
milestone1_project1,
milestone1_project2,
milestone1_project3,
milestone2_project1,
milestone2_project2,
milestone2_project3
]
it 'should have all project milestones' do
expect(@group_milestones.count).to eq(2)
end
@global_milestones = GlobalMilestone.build_collection(milestones)
end
it 'should have all project milestones' do
expect(@global_milestones.count).to eq(2)
end
it 'should have all project milestones titles' do
expect(@group_milestones.map { |group_milestone| group_milestone.title }).to match_array(['Milestone v1.2', 'VD-123'])
end
it 'should have all project milestones titles' do
expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123'])
end
it 'should have all project milestones' do
expect(@group_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
end
it 'should have all project milestones' do
expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
end
end
describe 'milestone' do
context 'with valid title' do
before do
milestones =
[
milestone1_project1,
milestone1_project2,
milestone1_project3,
milestone2_project1,
milestone2_project2,
milestone2_project3
]
@group_milestones = Milestones::GroupService.new(milestones).milestone('Milestone v1.2')
end
describe :initialize do
before do
milestones =
[
milestone1_project1,
milestone1_project2,
milestone1_project3,
]
it 'should have exactly one group milestone' do
expect(@group_milestones.title).to eq('Milestone v1.2')
end
@global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones)
end
it 'should have exactly one group milestone' do
expect(@global_milestone.title).to eq('Milestone v1.2')
end
it 'should have all project milestones with the same title' do
expect(@group_milestones.milestones.count).to eq(3)
end
it 'should have all project milestones with the same title' do
expect(@global_milestone.milestones.count).to eq(3)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment