Send an empty CSV file for invalid user segments
We were getting an exception in this case, which was OK I guess since this shouldn't happen if the application is used in a normal way, but we can simplify the code a little bit if we make the `recipients` code return an empty list of users. Note that the behavior of the `AdminNotification#list_of_recipients` and `Newsletter#list_of_recipient_emails` methods is now slightly different; previously they returned `nil` when given an invalid segment recipient, while now they return an empty array. I haven't found a place where this change is relevant. For example, in both of these models, the `deliver` method used to raise an exception when given an invalid segment while now it doesn't, but we always check the user segment is valid before calling the `deliver` method anyway, so it doesn't really affect the application.
This commit is contained in:
@@ -25,7 +25,7 @@ class AdminNotification < ApplicationRecord
|
||||
end
|
||||
|
||||
def list_of_recipients_count
|
||||
list_of_recipients&.count || 0
|
||||
list_of_recipients.count
|
||||
end
|
||||
|
||||
def deliver
|
||||
|
||||
@@ -11,7 +11,7 @@ class Newsletter < ApplicationRecord
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
def list_of_recipient_emails
|
||||
UserSegments.user_segment_emails(segment_recipient) if valid_segment_recipient?
|
||||
UserSegments.user_segment_emails(segment_recipient)
|
||||
end
|
||||
|
||||
def valid_segment_recipient?
|
||||
|
||||
Reference in New Issue
Block a user