Skip to content

Commit

Permalink
Filter out nil and empty string when bulk processing emails
Browse files Browse the repository at this point in the history
Seems harmless to filter these out.

Also bump the minor version on the gem so we can publish.
  • Loading branch information
QuotableWater7 committed Jun 29, 2016
1 parent a15c873 commit 31da455
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/email_repair/mechanic.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module EmailRepair

class Mechanic

def repairs
[
CommonMistakeRepair,
Expand All @@ -12,6 +14,8 @@ def repairs
end

def repair_all(emails)
emails = emails.reject(&:nil?).map(&:strip).reject { |email| email == '' }

sanitized_emails = []
invalid_emails = []

Expand Down
2 changes: 1 addition & 1 deletion lib/email_repair/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module EmailRepair
VERSION = '0.0.3'
VERSION = '0.1.0'
end
10 changes: 10 additions & 0 deletions spec/lib/email_repair/mechanic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ module EmailRepair
expect(result.invalid_emails).to match_array bad_emails
end

it 'filters out nil and empty string emails before processing results' do
mechanic = Mechanic.new
emails = [nil, '', ' ', 'bleep@bloop.com']

result = mechanic.repair_all(emails)

expect(result.sanitized_emails).to eq ['bleep@bloop.com']
expect(result.invalid_emails).to eq []
end

end

describe Mechanic, '#repair' do
Expand Down

0 comments on commit 31da455

Please sign in to comment.