summaryrefslogtreecommitdiff
path: root/app/models/concerns/issuable.rb
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/concerns/issuable.rb
parent125c07fa0aa31e6c83c8fcc90df623c2ef85832f (diff)
downloadgitlab-ce-7047a44a26f0f75ab23c58c47d096060c01256ed.tar.gz
Sett iid on create. Use iid as value to_param
Diffstat (limited to 'app/models/concerns/issuable.rb')
-rw-r--r--app/models/concerns/issuable.rb12
1 files changed, 12 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