2016-04-16 15:09:08 -04:00
|
|
|
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
|
2016-06-25 17:48:12 -04:00
|
|
|
validates :name, presence: true, inclusion: { in: Gitlab::Emoji.emojis_names }
|
2016-04-16 15:09:08 -04:00
|
|
|
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
|
|
|
|
end
|