docbrown/app/services/notification_subscriptions/update.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

28 lines
587 B
Ruby

module NotificationSubscriptions
class Update
def initialize(notifiable)
@notifiable = notifiable
end
def self.call(...)
new(...).call
end
def call
return unless [Article].include?(notifiable.class)
notification_subscriptions = NotificationSubscription.where(
notifiable_id: notifiable.id,
notifiable_type: notifiable.class.name,
)
return if notification_subscriptions.none?
notification_subscriptions.update_all(user_id: notifiable.user_id)
end
private
attr_reader :notifiable
end
end