debian-mirror-gitlab/spec/models/group_milestone_spec.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

2019-05-18 00:54:41 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2017-09-10 17:25:29 +05:30
describe GroupMilestone do
2017-08-17 22:00:37 +05:30
let(:group) { create(:group) }
2017-09-10 17:25:29 +05:30
let(:project) { create(:project, group: group) }
2017-08-17 22:00:37 +05:30
let(:project_milestone) do
create(:milestone, title: "Milestone v1.2", project: project)
end
describe '.build' do
it 'returns milestone with group assigned' do
2017-09-10 17:25:29 +05:30
milestone = described_class.build(
2017-08-17 22:00:37 +05:30
group,
[project],
project_milestone.title
)
expect(milestone.group).to eq group
end
end
describe '.build_collection' do
2019-02-15 15:39:39 +05:30
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!(:projects) do
[
project1,
project2,
project3
]
2017-08-17 22:00:37 +05:30
end
it 'returns array of milestones, each with group assigned' do
2017-09-10 17:25:29 +05:30
milestones = described_class.build_collection(group, [project], {})
2017-08-17 22:00:37 +05:30
expect(milestones).to all(have_attributes(group: group))
end
2019-02-15 15:39:39 +05:30
context 'when adding new milestones' do
it 'does not add more queries' do
control_count = ActiveRecord::QueryRecorder.new do
described_class.build_collection(group, projects, {})
end.count
create(:milestone, title: 'This title', project: project1)
expect do
described_class.build_collection(group, projects, {})
end.not_to exceed_all_query_limit(control_count)
end
end
2017-08-17 22:00:37 +05:30
end
end