summaryrefslogtreecommitdiff
path: root/spec/models/milestone_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/milestone_spec.rb')
-rw-r--r--spec/models/milestone_spec.rb163
1 files changed, 21 insertions, 142 deletions
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index ee4c35ebddd..e51108947a7 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -3,8 +3,10 @@
require 'spec_helper'
describe Milestone do
+ it_behaves_like 'a timebox', :milestone
+
describe 'MilestoneStruct#serializable_hash' do
- let(:predefined_milestone) { described_class::MilestoneStruct.new('Test Milestone', '#test', 1) }
+ let(:predefined_milestone) { described_class::TimeboxStruct.new('Test Milestone', '#test', 1) }
it 'presents the predefined milestone as a hash' do
expect(predefined_milestone.serializable_hash).to eq(
@@ -15,69 +17,11 @@ describe Milestone do
end
end
- describe 'modules' do
- context 'with a project' do
- it_behaves_like 'AtomicInternalId' do
- let(:internal_id_attribute) { :iid }
- let(:instance) { build(:milestone, project: build(:project), group: nil) }
- let(:scope) { :project }
- let(:scope_attrs) { { project: instance.project } }
- let(:usage) { :milestones }
- end
- end
-
- context 'with a group' do
- it_behaves_like 'AtomicInternalId' do
- let(:internal_id_attribute) { :iid }
- let(:instance) { build(:milestone, project: nil, group: build(:group)) }
- let(:scope) { :group }
- let(:scope_attrs) { { namespace: instance.group } }
- let(:usage) { :milestones }
- end
- end
- end
-
describe "Validation" do
before do
allow(subject).to receive(:set_iid).and_return(false)
end
- describe 'start_date' do
- it 'adds an error when start_date is greater then due_date' do
- milestone = build(:milestone, start_date: Date.tomorrow, due_date: Date.yesterday)
-
- expect(milestone).not_to be_valid
- expect(milestone.errors[:due_date]).to include("must be greater than start date")
- end
-
- it 'adds an error when start_date is greater than 9999-12-31' do
- milestone = build(:milestone, start_date: Date.new(10000, 1, 1))
-
- expect(milestone).not_to be_valid
- expect(milestone.errors[:start_date]).to include("date must not be after 9999-12-31")
- end
- end
-
- describe 'due_date' do
- it 'adds an error when due_date is greater than 9999-12-31' do
- milestone = build(:milestone, due_date: Date.new(10000, 1, 1))
-
- expect(milestone).not_to be_valid
- expect(milestone.errors[:due_date]).to include("date must not be after 9999-12-31")
- end
- end
-
- describe 'title' do
- it { is_expected.to validate_presence_of(:title) }
-
- it 'is invalid if title would be empty after sanitation' do
- milestone = build(:milestone, project: project, title: '<img src=x onerror=prompt(1)>')
-
- expect(milestone).not_to be_valid
- expect(milestone.errors[:title]).to include("can't be blank")
- end
- end
-
describe 'milestone_releases' do
let(:milestone) { build(:milestone, project: project) }
@@ -99,8 +43,6 @@ describe Milestone do
end
describe "Associations" do
- it { is_expected.to belong_to(:project) }
- it { is_expected.to have_many(:issues) }
it { is_expected.to have_many(:releases) }
it { is_expected.to have_many(:milestone_releases) }
end
@@ -110,87 +52,6 @@ describe Milestone do
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
- describe "#title" do
- let(:milestone) { create(:milestone, title: "<b>foo & bar -> 2.2</b>") }
-
- it "sanitizes title" do
- expect(milestone.title).to eq("foo & bar -> 2.2")
- end
- end
-
- describe '#merge_requests_enabled?' do
- context "per project" do
- it "is true for projects with MRs enabled" do
- project = create(:project, :merge_requests_enabled)
- milestone = create(:milestone, project: project)
-
- expect(milestone.merge_requests_enabled?).to be(true)
- end
-
- it "is false for projects with MRs disabled" do
- project = create(:project, :repository_enabled, :merge_requests_disabled)
- milestone = create(:milestone, project: project)
-
- expect(milestone.merge_requests_enabled?).to be(false)
- end
-
- it "is false for projects with repository disabled" do
- project = create(:project, :repository_disabled)
- milestone = create(:milestone, project: project)
-
- expect(milestone.merge_requests_enabled?).to be(false)
- end
- end
-
- context "per group" do
- let(:group) { create(:group) }
- let(:milestone) { create(:milestone, group: group) }
-
- it "is always true for groups, for performance reasons" do
- expect(milestone.merge_requests_enabled?).to be(true)
- end
- end
- end
-
- describe "unique milestone title" do
- context "per project" do
- it "does not accept the same title in a project twice" do
- new_milestone = described_class.new(project: milestone.project, title: milestone.title)
- expect(new_milestone).not_to be_valid
- end
-
- it "accepts the same title in another project" do
- project = create(:project)
- new_milestone = described_class.new(project: project, title: milestone.title)
-
- expect(new_milestone).to be_valid
- end
- end
-
- context "per group" do
- let(:group) { create(:group) }
- let(:milestone) { create(:milestone, group: group) }
-
- before do
- project.update(group: group)
- end
-
- it "does not accept the same title in a group twice" do
- new_milestone = described_class.new(group: group, title: milestone.title)
-
- expect(new_milestone).not_to be_valid
- end
-
- it "does not accept the same title of a child project milestone" do
- create(:milestone, project: group.projects.first)
-
- new_milestone = described_class.new(group: group, title: milestone.title)
-
- expect(new_milestone).not_to be_valid
- end
- end
- end
-
describe '.predefined_id?' do
it 'returns true for a predefined Milestone ID' do
expect(Milestone.predefined_id?(described_class::Upcoming.id)).to be true
@@ -619,4 +480,22 @@ describe Milestone do
it { is_expected.not_to match("#{Gitlab.config.gitlab.url}/gitlab-org/gitlab-foss/issues/123") }
it { is_expected.not_to match("gitlab-org/gitlab-ce/milestones/123") }
end
+
+ describe '#parent' do
+ context 'with group' do
+ it 'returns the expected parent' do
+ group = create(:group)
+
+ expect(build(:milestone, group: group).parent).to eq(group)
+ end
+ end
+
+ context 'with project' do
+ it 'returns the expected parent' do
+ project = create(:project)
+
+ expect(build(:milestone, project: project).parent).to eq(project)
+ end
+ end
+ end
end