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.
19 lines
466 B
Ruby
19 lines
466 B
Ruby
class Admin::EmailsDownloadController < Admin::BaseController
|
|
def index
|
|
end
|
|
|
|
def generate_csv
|
|
users_segment = params[:users_segment]
|
|
filename = t("admin.segment_recipient.#{users_segment}")
|
|
|
|
csv_file = users_segment_emails_csv(users_segment)
|
|
send_data csv_file, filename: "#{filename}.csv"
|
|
end
|
|
|
|
private
|
|
|
|
def users_segment_emails_csv(users_segment)
|
|
UserSegments.send(users_segment).newsletter.pluck(:email).compact.join(',')
|
|
end
|
|
end
|