Remove empty emails from users segments recipients

Why:

User with an empty email value (nil) should not appear in the recipient
list for a given UserSegment at Newsletters or Email Downloads.

How:

Using Enumerable#compact and Enumerable#select to filter out empty emails

Increasing Email Download feature spec and Newsletter model spec to cover
all possible scenarios including the nil email one.
This commit is contained in:
Bertocq
2018-03-01 19:47:53 +01:00
parent 089cef8ead
commit 99851e9588
4 changed files with 37 additions and 17 deletions

View File

@@ -13,6 +13,6 @@ class Admin::EmailsDownloadController < Admin::BaseController
private
def users_segment_emails_csv(users_segment)
UserSegments.send(users_segment).newsletter.pluck(:email).to_csv
UserSegments.send(users_segment).newsletter.pluck(:email).compact.join(',')
end
end