summaryrefslogtreecommitdiff
path: root/app/models/award_emoji.rb
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-04-16 21:09:08 +0200
committerZeger-Jan van de Weg <zegerjan@gitlab.com>2016-05-06 10:47:11 +0200
commit3bdc57f0a710b3769381ecad7ea4098223ecff56 (patch)
treeabfe22d7d40c7d3e2912d659b045273254767dea /app/models/award_emoji.rb
parent05920a7964a039fd65d6b665c2ebd130d5ef949c (diff)
downloadgitlab-ce-3bdc57f0a710b3769381ecad7ea4098223ecff56.tar.gz
Create table for award emoji
Diffstat (limited to 'app/models/award_emoji.rb')
-rw-r--r--app/models/award_emoji.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb
new file mode 100644
index 00000000000..44a9b55a8a6
--- /dev/null
+++ b/app/models/award_emoji.rb
@@ -0,0 +1,35 @@
+class AwardEmoji < ActiveRecord::Base
+ DOWNVOTE_NAME = "thumbsdown".freeze
+ UPVOTE_NAME = "thumbsup".freeze
+
+ include Participable
+
+ belongs_to :awardable, polymorphic: true
+ belongs_to :user
+
+ validates :awardable, :user, presence: true
+ validates :name, presence: true, inclusion: { in: Emoji.emojis_names }
+ validates :name, uniqueness: { scope: [:user, :awardable_type, :awardable_id] }
+
+ participant :user
+
+ scope :downvotes, -> { where(name: DOWNVOTE_NAME) }
+ scope :upvotes, -> { where(name: UPVOTE_NAME) }
+
+ def downvote?
+ self.name == DOWNVOTE_NAME
+ end
+
+ def upvote?
+ self.name == UPVOTE_NAME
+ end
+
+ def to_note_json
+ {
+ valid: valid?,
+ award: true,
+ id: id,
+ name: name
+ }
+ end
+end