FIX: nil emails are invalid

This commit is contained in:
Sam 2015-05-27 14:12:10 +10:00
parent 02fa7448ca
commit 693b5234da
2 changed files with 7 additions and 0 deletions

View File

@ -7,6 +7,9 @@ require_dependency 'email/styles'
module Email
def self.is_valid?(email)
return false unless String === email
parser = Mail::RFC2822Parser.new
parser.root = :addr_spec
result = parser.parse(email)

View File

@ -5,6 +5,10 @@ describe Email do
describe "is_valid?" do
it 'treats a nil as invalid' do
expect(Email.is_valid?(nil)).to eq(false)
end
it 'treats a good email as valid' do
expect(Email.is_valid?('sam@sam.com')).to eq(true)
end