summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-19 22:10:56 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-08-19 22:10:56 +0300
commit7047a44a26f0f75ab23c58c47d096060c01256ed (patch)
treeee3e07554c2669597a352107eca62f27fe60b32d /app/models
parent125c07fa0aa31e6c83c8fcc90df623c2ef85832f (diff)
downloadgitlab-ce-7047a44a26f0f75ab23c58c47d096060c01256ed.tar.gz
Sett iid on create. Use iid as value to_param
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/issuable.rb12
-rw-r--r--app/models/merge_request.rb4
2 files changed, 16 insertions, 0 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb
index 91fb323825d..158c226480f 100644
--- a/app/models/concerns/issuable.rb
+++ b/app/models/concerns/issuable.rb
@@ -16,6 +16,7 @@ module Issuable
validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 }
+ validates :iid, presence: true, numericality: true
scope :authored, ->(user) { where(author_id: user) }
scope :assigned_to, ->(u) { where(assignee_id: u.id)}
@@ -24,6 +25,8 @@ module Issuable
scope :unassigned, -> { where("assignee_id IS NULL") }
scope :of_projects, ->(ids) { where(project_id: ids) }
+ validate :set_iid, on: :create
+
delegate :name,
:email,
to: :author,
@@ -44,6 +47,15 @@ module Issuable
end
end
+ def set_iid
+ max_iid = project.send(self.class.name.tableize).maximum(:iid)
+ self.iid = max_iid.to_i + 1
+ end
+
+ def to_param
+ iid.to_s
+ end
+
def today?
Date.today == created_at.to_date
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index b7df2e40a16..d525ad17537 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -250,6 +250,10 @@ class MergeRequest < ActiveRecord::Base
(source_project.root_ref? source_branch) || for_fork?
end
+ def project
+ target_project
+ end
+
private
def dump_commits(commits)