From db6385f799bbbe97f30cbab1edefab4edf7f77fc Mon Sep 17 00:00:00 2001 From: Bryan Moreno Date: Fri, 22 Sep 2017 15:06:32 -0300 Subject: [PATCH 1/3] Fix the name extraction when empty strings are provided --- lib/griddler/email_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/griddler/email_parser.rb b/lib/griddler/email_parser.rb index 11de6f48..b32dd74a 100644 --- a/lib/griddler/email_parser.rb +++ b/lib/griddler/email_parser.rb @@ -65,7 +65,7 @@ def self.extract_email_address(full_address) def self.extract_name(full_address) full_address = full_address.strip - name = full_address.split('<').first.strip + name = full_address&.split('<')&.first&.strip if name.present? && name != full_address name end From 765691176934ad9395fb8a169498c6bf9b3527ed Mon Sep 17 00:00:00 2001 From: Bryan Moreno Date: Fri, 22 Sep 2017 15:21:10 -0300 Subject: [PATCH 2/3] Remove unnecessary &'s --- lib/griddler/email_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/griddler/email_parser.rb b/lib/griddler/email_parser.rb index b32dd74a..819a3294 100644 --- a/lib/griddler/email_parser.rb +++ b/lib/griddler/email_parser.rb @@ -65,7 +65,7 @@ def self.extract_email_address(full_address) def self.extract_name(full_address) full_address = full_address.strip - name = full_address&.split('<')&.first&.strip + name = full_address.split('<').first&.strip if name.present? && name != full_address name end From a23aa2f9000a8d52f8d8c79c7f7046ab0311d8c8 Mon Sep 17 00:00:00 2001 From: Bryan Moreno Date: Fri, 22 Sep 2017 15:46:26 -0300 Subject: [PATCH 3/3] Add specs for the empty names --- .ruby-version | 2 +- .travis.yml | 1 + griddler.gemspec | 4 ++-- spec/griddler/email_spec.rb | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.ruby-version b/.ruby-version index b1b25a5f..005119ba 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.2.2 +2.4.1 diff --git a/.travis.yml b/.travis.yml index 69ffe076..13038f50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ rvm: - 2.0 - 2.1 - 2.2 + - 2.4 env: - "RAILS_BRANCH=4-1-stable" - "RAILS_BRANCH=4-2-stable" diff --git a/griddler.gemspec b/griddler.gemspec index 227364e6..1a17511c 100644 --- a/griddler.gemspec +++ b/griddler.gemspec @@ -10,11 +10,11 @@ Gem::Specification.new do |s| s.homepage = 'http://thoughtbot.com' s.summary = 'SendGrid Parse API client Rails Engine' - s.required_ruby_version = Gem::Requirement.new(">= 1.9.2") + s.required_ruby_version = Gem::Requirement.new(">= 2.4.1") s.files = Dir['{app,config,lib}/**/*'] + ['LICENSE', 'Rakefile', 'README.md'] s.require_paths = %w{app lib} - s.add_dependency 'rails', '>= 3.2.0' + s.add_dependency 'rails', '>= 4.2.0' s.add_dependency 'htmlentities' s.add_development_dependency 'rspec-rails' s.add_development_dependency 'sqlite3' diff --git a/spec/griddler/email_spec.rb b/spec/griddler/email_spec.rb index 1e1c7c88..c857cd7f 100644 --- a/spec/griddler/email_spec.rb +++ b/spec/griddler/email_spec.rb @@ -582,6 +582,23 @@ def header_from_email(header) end + it 'handles empty names' do + email = Griddler::Email.new( + text: 'hi', + to: [' '], + from: @full_address + ) + expected = { + token: nil, + host: nil, + email: '', + full: ' ', + name: nil + } + expect(email.to).to eq [expected] + expect(email.from).to eq @address_components + end + it 'returns the BCC email' do email = Griddler::Email.new( text: 'hi',