Sha256: dafb058438b5a9251b4ada6232aac51d3f86e43f290128166d853fb0b64c980f

Contents?: true

Size: 943 Bytes

Versions: 1

Compression:

Stored size: 943 Bytes

Contents

class BrainstormingIdeaVote < ActiveRecord::Base
  belongs_to :idea, class_name: 'BrainstormingIdea', counter_cache: 'votes_count'
  belongs_to :user
  
  validates :idea_id, presence: true
  validates :user_id, presence: true, uniqueness: { scope: :idea_id }
  
  attr_accessible :idea_id
  
  after_create :publish_create
  after_destroy :publish_destroy
  
  private
  
  def publish_create
    return if Rails.env.test? || Rails.env.cucumber?
    
    MessageBus.publish(
      "/brainstormings/#{idea.brainstorming.slug}", 
      { message: "#{I18n.t('brainstorming_idea_votes.model.publish_create')}: +1 #{idea.name} by #{user.name}" }
    )
  end
  
  def publish_destroy
    return if Rails.env.test? || Rails.env.cucumber?
    
    MessageBus.publish(
      "/brainstormings/#{idea.brainstorming.slug}", 
      { message: "#{I18n.t('brainstorming_idea_votes.model.publish_destroy')}: -1 #{idea.name} by #{user.name}" }
    )
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voluntary_brainstorming-0.0.2 app/models/brainstorming_idea_vote.rb