app/models/stock.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Stock < ActiveRecord::Base
  belongs_to :user
  belongs_to :article
  after_create :create_notification

  validates_uniqueness_of :user_id, :scope => :article_id

  def create_notification
    article = self.article
    return if self.user_id == article.user_id
    notification = StockNotification.create!(
      user_id: self.user_id,
      state: :create,
      article_id: article.id,
    )
    notification.create_targets_for_owner_by_article(article)
  end
end