docbrown/app/models/notification_subscription.rb
Lewis Sparlin e621659279
Add Article post_commit when user_id changes with specs (#15132)
* Add Article post_commit when user_id changes with specs

* Add example in requests/admin/articles_spec for updating user
2021-10-25 10:53:21 +07:00

18 lines
647 B
Ruby

class NotificationSubscription < ApplicationRecord
belongs_to :notifiable, polymorphic: true
belongs_to :user
validates :config, presence: true, inclusion: { in: %w[all_comments top_level_comments only_author_comments] }
validates :notifiable_id, presence: true
validates :notifiable_type, presence: true, inclusion: { in: %w[Comment Article] }
validates :user_id, uniqueness: { scope: %i[notifiable_type notifiable_id] }
class << self
def update_notification_subscriptions(notifiable)
NotificationSubscriptions::UpdateWorker.perform_async(
notifiable.id,
notifiable.class.name,
)
end
end
end