diff options
author | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-04-16 21:09:08 +0200 |
---|---|---|
committer | Zeger-Jan van de Weg <zegerjan@gitlab.com> | 2016-05-06 10:47:11 +0200 |
commit | 3bdc57f0a710b3769381ecad7ea4098223ecff56 (patch) | |
tree | abfe22d7d40c7d3e2912d659b045273254767dea /app/models/award_emoji.rb | |
parent | 05920a7964a039fd65d6b665c2ebd130d5ef949c (diff) | |
download | gitlab-ce-3bdc57f0a710b3769381ecad7ea4098223ecff56.tar.gz |
Create table for award emoji
Diffstat (limited to 'app/models/award_emoji.rb')
-rw-r--r-- | app/models/award_emoji.rb | 35 |
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 |