summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <mail@zjvandeweg.nl>2016-02-02 10:44:30 +0100
committerZeger-Jan van de Weg <mail@zjvandeweg.nl>2016-02-08 12:45:32 +0100
commit308c967d0dee4b56613d4b285fbd0cf0a1c3ce69 (patch)
treec91a37f7c7903b278f2a66c60c83ace7d59ffeef
parent05519b554a49057f6551595a3bc3f01e140f3c0b (diff)
downloadgitlab-ce-308c967d0dee4b56613d4b285fbd0cf0a1c3ce69.tar.gz
Validate uniqueness of milestone title per project
Fixes #3903
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/milestone.rb2
-rw-r--r--spec/models/milestone_spec.rb14
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 983a219703a..25acdbcb485 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -35,6 +35,7 @@ v 8.5.0 (unreleased)
- Fixed logo animation on Safari (Roman Rott)
- Hide remove source branch button when the MR is merged but new commits are pushed (Zeger-Jan van de Weg)
- In seach autocomplete show only groups and projects you are member of
+ - Title for milestones should be unique (Zeger-Jan van de Weg)
v 8.4.4
- Update omniauth-saml gem to 1.4.2
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index c9a0ad8b9b6..9c4476c768e 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -34,7 +34,7 @@ class Milestone < ActiveRecord::Base
scope :closed, -> { with_state(:closed) }
scope :of_projects, ->(ids) { where(project_id: ids) }
- validates :title, presence: true
+ validates :title, presence: true, uniqueness: { scope: :project_id }
validates :project, presence: true
strip_attributes :title
diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb
index 30a71987d86..1b1380ce4e2 100644
--- a/spec/models/milestone_spec.rb
+++ b/spec/models/milestone_spec.rb
@@ -33,6 +33,20 @@ describe Milestone, models: true do
let(:milestone) { create(:milestone) }
let(:issue) { create(:issue) }
+ describe "unique milestone title per project" do
+ it "shouldn't accept the same title in a project twice" do
+ new_milestone = Milestone.new(project: milestone.project, title: milestone.title)
+ expect(new_milestone).not_to be_valid
+ end
+
+ it "should accept the same title in another project" do
+ project = build(:project)
+ new_milestone = Milestone.new(project: project, title: milestone.title)
+
+ expect(new_milestone).to be_valid
+ end
+ end
+
describe "#percent_complete" do
it "should not count open issues" do
milestone.issues << issue