Test case sensitivity

This commit is contained in:
Lee Reilly 2012-02-04 20:57:29 -08:00
parent 367c36d244
commit 7e652bce3a
2 changed files with 26 additions and 9 deletions

View File

@ -101,17 +101,28 @@ module Swot
# Returns true if the domain name belongs to an academic institution;
# false oterwise.
def is_academic?(text)
return false if text.nil?
text.downcase!
text = text.split("@")[1] if text.include? "@"
domain = PublicSuffix.parse(text)
if ACADEMIC_TLDS.include?(domain.tld)
true
elsif match_academic_domain?(domain)
true
else
false
begin
domain = PublicSuffix.parse(text)
if ACADEMIC_TLDS.include?(domain.tld)
true
elsif match_academic_domain?(domain)
true
else
false
end
rescue PublicSuffix::DomainInvalid => di
return false
rescue PublicSuffix::DomainNotAllowed => dna
return false
end
end
# Figure out if a domain name is a know academic institution.

View File

@ -1,8 +1,10 @@
require 'helper'
class TestEmail < Test::Unit::TestCase
should "work with all the things" do
should "recognizes academic email addresses and domains" do
assert_equal Swot::is_academic?('lreilly@stanford.edu'), true
assert_equal Swot::is_academic?('LREILLY@STANFORD.EDU'), true
assert_equal Swot::is_academic?('Lreilly@Stanford.Edu'), true
assert_equal Swot::is_academic?('lreilly@slac.stanford.edu'), true
assert_equal Swot::is_academic?('lreilly@strath.ac.uk'), true
assert_equal Swot::is_academic?('lreilly@soft-eng.strath.ac.uk'), true
@ -33,5 +35,9 @@ class TestEmail < Test::Unit::TestCase
assert_equal Swot::is_academic?('stanford.edu.com'), false
assert_equal Swot::is_academic?('strath.ac.uk.com'), false
assert_equal Swot::is_academic?(nil), false
assert_equal Swot::is_academic?(''), false
assert_equal Swot::is_academic?('the'), false
end
end