diff options
Diffstat (limited to 'spec/models/milestone_spec.rb')
-rw-r--r-- | spec/models/milestone_spec.rb | 143 |
1 files changed, 2 insertions, 141 deletions
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index ee4c35ebddd..e6544fda640 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -3,6 +3,8 @@ 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) } @@ -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 |