Don't notify while bubbles are still drafted
This commit is contained in:
@@ -14,8 +14,8 @@ module NotificationsHelper
|
||||
|
||||
case notification.event.action
|
||||
when "assigned" then "#{name} assigned to you"
|
||||
when "published" then "Added by #{name}"
|
||||
when "popped" then "Popped by by #{name}"
|
||||
when "published" then notification_bubble_created_message(notification)
|
||||
else name
|
||||
end
|
||||
end
|
||||
@@ -24,4 +24,13 @@ module NotificationsHelper
|
||||
link_to notification.resource, id: dom_id(notification), class: "notification border-radius",
|
||||
data: { turbo_frame: "_top" }, &
|
||||
end
|
||||
|
||||
private
|
||||
def notification_bubble_created_message(notification)
|
||||
if notification.bubble.assigned_to?(notification.user)
|
||||
"#{notification.creator.name} assigned to you"
|
||||
else
|
||||
"Added by #{notification.creator.name}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,8 +10,10 @@ class Notifier
|
||||
end
|
||||
|
||||
def generate
|
||||
recipients.map do |recipient|
|
||||
Notification.create! user: recipient, event: event, bubble: bubble, resource: resource
|
||||
if should_notify?
|
||||
recipients.map do |recipient|
|
||||
Notification.create! user: recipient, event: event, bubble: bubble, resource: resource
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,6 +22,10 @@ class Notifier
|
||||
@event = event
|
||||
end
|
||||
|
||||
def should_notify?
|
||||
bubble.published?
|
||||
end
|
||||
|
||||
def recipients
|
||||
bubble.bucket.users.without(creator)
|
||||
end
|
||||
|
||||
@@ -12,4 +12,18 @@ class NotifierTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "generate creates notifications for the event recipients" do
|
||||
assert_difference -> { Notification.count }, +2 do
|
||||
Notifier.for(events(:logo_published)).generate
|
||||
end
|
||||
end
|
||||
|
||||
test "generate does not create notifications if the bubble is not published" do
|
||||
bubbles(:logo).drafted!
|
||||
|
||||
assert_no_difference -> { Notification.count } do
|
||||
Notifier.for(events(:logo_published)).generate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user