2013-02-06 03:16:51 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'email'
|
|
|
|
|
|
|
|
describe Email do
|
|
|
|
|
2013-04-15 08:20:33 +08:00
|
|
|
describe "is_valid?" do
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-04-15 08:20:33 +08:00
|
|
|
it 'treats a good email as valid' do
|
|
|
|
Email.is_valid?('sam@sam.com').should be_true
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
|
2013-04-15 08:20:33 +08:00
|
|
|
it 'treats a bad email as invalid' do
|
|
|
|
Email.is_valid?('sam@sam').should be_false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'allows museum tld' do
|
|
|
|
Email.is_valid?('sam@nic.museum').should be_true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not think a word is an email' do
|
|
|
|
Email.is_valid?('sam').should be_false
|
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-02-26 00:42:20 +08:00
|
|
|
|
2013-04-15 08:20:33 +08:00
|
|
|
describe "downcase" do
|
|
|
|
|
2014-07-14 22:16:24 +08:00
|
|
|
it 'downcases local and host part' do
|
|
|
|
Email.downcase('SAM@GMAIL.COM').should == 'sam@gmail.com'
|
|
|
|
Email.downcase('sam@GMAIL.COM').should == 'sam@gmail.com'
|
2013-04-15 08:20:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'leaves invalid emails untouched' do
|
|
|
|
Email.downcase('SAM@GMAILCOM').should == 'SAM@GMAILCOM'
|
|
|
|
Email.downcase('samGMAIL.COM').should == 'samGMAIL.COM'
|
|
|
|
Email.downcase('sam@GM@AIL.COM').should == 'sam@GM@AIL.COM'
|
|
|
|
end
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
2013-04-15 08:20:33 +08:00
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|