BigW Consortium Gitlab

global_milestone_spec.rb 2.43 KB
Newer Older
1 2
require 'spec_helper'

Douwe Maan committed
3
describe GlobalMilestone, models: true do
4 5 6 7 8 9 10 11 12 13 14 15 16
  let(:user) { create(:user) }
  let(:user2) { create(:user) }
  let(:group) { create(:group) }
  let(:project1) { create(:project, group: group) }
  let(:project2) { create(:project, path: 'gitlab-ci', group: group) }
  let(:project3) { create(:project, path: 'cookbook-gitlab', group: group) }
  let(:milestone1_project1) { create(:milestone, title: "Milestone v1.2", project: project1) }
  let(:milestone1_project2) { create(:milestone, title: "Milestone v1.2", project: project2) }
  let(:milestone1_project3) { create(:milestone, title: "Milestone v1.2", project: project3) }
  let(:milestone2_project1) { create(:milestone, title: "VD-123", project: project1) }
  let(:milestone2_project2) { create(:milestone, title: "VD-123", project: project2) }
  let(:milestone2_project3) { create(:milestone, title: "VD-123", project: project3) }

17
  describe '.build_collection' do
18 19 20 21 22 23 24 25 26 27 28 29 30 31
    before do
      milestones =
        [
          milestone1_project1,
          milestone1_project2,
          milestone1_project3,
          milestone2_project1,
          milestone2_project2,
          milestone2_project3
        ]

      @global_milestones = GlobalMilestone.build_collection(milestones)
    end

32
    it 'has all project milestones' do
33 34 35
      expect(@global_milestones.count).to eq(2)
    end

36
    it 'has all project milestones titles' do
37 38 39
      expect(@global_milestones.map(&:title)).to match_array(['Milestone v1.2', 'VD-123'])
    end

40
    it 'has all project milestones' do
41 42 43 44
      expect(@global_milestones.map { |group_milestone| group_milestone.milestones.count }.sum).to eq(6)
    end
  end

45
  describe '#initialize' do
46 47 48 49 50 51 52 53 54 55 56
    before do
      milestones =
        [
          milestone1_project1,
          milestone1_project2,
          milestone1_project3,
        ]

      @global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones)
    end

57
    it 'has exactly one group milestone' do
58 59 60
      expect(@global_milestone.title).to eq('Milestone v1.2')
    end

61
    it 'has all project milestones with the same title' do
62 63 64
      expect(@global_milestone.milestones.count).to eq(3)
    end
  end
65

66
  describe '#safe_title' do
67 68
    let(:milestone) { create(:milestone, title: "git / test", project: project1) }

69
    it 'strips out slashes and spaces' do
70 71 72 73 74
      global_milestone = GlobalMilestone.new(milestone.title, [milestone])

      expect(global_milestone.safe_title).to eq('git-test')
    end
  end
75
end