Skip to content
This repository was archived by the owner on Jul 12, 2024. It is now read-only.

Commit 67a78e4

Browse files
Make the code resilient against an empty recipient.
1 parent 179b706 commit 67a78e4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/griddler/email.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def config
3737
end
3838

3939
def recipients(type)
40-
params[type].to_a.map { |recipient| extract_address(recipient) }
40+
params[type].to_a.reject(&:empty?).map do |recipient|
41+
extract_address(recipient)
42+
end
4143
end
4244

4345
def extract_address(address)

spec/griddler/email_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,4 +783,19 @@ def header_from_email(header)
783783
expect(email.to.map { |to| to[:full] }).to eq recipients
784784
end
785785
end
786+
787+
context 'with an empty recipient in to field' do
788+
it 'includes all of the emails' do
789+
recipients =
790+
791+
'',
792+
793+
'Swift <[email protected]>']
794+
params = { to: recipients, from: '[email protected]', text: 'hi guys' }
795+
796+
email = Griddler::Email.new(params)
797+
798+
expect(email.to.map { |to| to[:full] }).to eq recipients.reject(&:empty?)
799+
end
800+
end
786801
end

0 commit comments

Comments
 (0)