diff --git a/app/models/concerns/push_notifiable.rb b/app/models/concerns/push_notifiable.rb index e7bfdc56a..4bf9b575d 100644 --- a/app/models/concerns/push_notifiable.rb +++ b/app/models/concerns/push_notifiable.rb @@ -2,8 +2,7 @@ module PushNotifiable extend ActiveSupport::Concern included do - after_create_commit :push_notification_later - after_update_commit :push_notification_later, if: :source_id_previously_changed? + after_save_commit :push_notification_later, if: :source_id_previously_changed? end private diff --git a/test/models/concerns/push_notifiable_test.rb b/test/models/concerns/push_notifiable_test.rb new file mode 100644 index 000000000..f6d7ed26d --- /dev/null +++ b/test/models/concerns/push_notifiable_test.rb @@ -0,0 +1,28 @@ +require "test_helper" + +class PushNotifiableTest < ActiveSupport::TestCase + test "enqueues push notification job when notification is created" do + assert_enqueued_with(job: PushNotificationJob) do + users(:david).notifications.create!( + source: events(:layout_published), + creator: users(:jason) + ) + end + end + + test "enqueues push notification job when notification source changes" do + notification = notifications(:logo_mentioned_david) + + assert_enqueued_with(job: PushNotificationJob) do + notification.update!(source: events(:logo_published)) + end + end + + test "does not enqueue push notification job for other updates" do + notification = notifications(:logo_mentioned_david) + + assert_no_enqueued_jobs only: PushNotificationJob do + notification.update!(unread_count: 5) + end + end +end