require 'helper' class AxleAttributes::FormatTest < ActiveSupport::TestCase test 'standardize_phone' do assert_equal nil, AxleAttributes::Format.standardize_phone(nil) assert_equal 'too4few', AxleAttributes::Format.standardize_phone('too4few') assert_equal '(222) 456-7890', AxleAttributes::Format.standardize_phone("2#2*2 \t4\n\n\n5()()()6.78====\\/===90!!!") assert_equal '(123) 456-7890', AxleAttributes::Format.standardize_phone('1234567890') assert_equal '(123) 456-7890', AxleAttributes::Format.standardize_phone(' (123) 456-7890 ') assert_equal '(123) 456-7890', AxleAttributes::Format.standardize_phone('1-123-456-7890 ') assert_equal '(800) 356-9377', AxleAttributes::Format.standardize_phone('1-800-FLOWERS') assert_equal '(800) 356-9377', AxleAttributes::Format.standardize_phone('1-800-flowers') assert_equal 'some string that is not a phone number', AxleAttributes::Format.standardize_phone('some string that is not a phone number') end test 'standardize_postal_code' do assert_equal nil, AxleAttributes::Format.standardize_postal_code(nil) assert_equal '', AxleAttributes::Format.standardize_postal_code('') assert_equal '12345', AxleAttributes::Format.standardize_postal_code('12345') assert_equal '12345', AxleAttributes::Format.standardize_postal_code('123 45') assert_equal '12345-6789', AxleAttributes::Format.standardize_postal_code('12345-6789') assert_equal '12345-6789', AxleAttributes::Format.standardize_postal_code('123456789') assert_equal 'H0H0H0', AxleAttributes::Format.standardize_postal_code('H0H0H0') assert_equal 'H0H0H0', AxleAttributes::Format.standardize_postal_code('h0h0h0') assert_equal 'H0H0H0', AxleAttributes::Format.standardize_postal_code('H0H 0H0') assert_equal 'Bogus Value', AxleAttributes::Format.standardize_postal_code('Bogus Value') end test "standardize_url" do assert_equal nil, AxleAttributes::Format.standardize_url(nil) assert_equal '', AxleAttributes::Format.standardize_url('') assert_equal 'website', AxleAttributes::Format.standardize_url('website') assert_equal '@twitter', AxleAttributes::Format.standardize_url('@twitter') assert_equal 'http://@twitter', AxleAttributes::Format.standardize_url('http://@twitter') assert_equal 'http://@twitter.com', AxleAttributes::Format.standardize_url('http://@twitter.com') assert_equal 'httpssss://www.twitter.com', AxleAttributes::Format.standardize_url('httpssss://www.twitter.com') assert_equal 'ftp://mywebsite.com', AxleAttributes::Format.standardize_url('ftp://mywebsite.com') assert_equal 'http:www.infogroup.com', AxleAttributes::Format.standardize_url('http:www.infogroup.com') assert_equal 'htp://www.infogroup.com', AxleAttributes::Format.standardize_url('htp://www.infogroup.com') assert_equal 'http::///www.infogroup.com', AxleAttributes::Format.standardize_url('http::///www.infogroup.com') assert_equal 'bad[twitter.com', AxleAttributes::Format.standardize_url('bad[twitter.com') assert_equal "http://www.infogroup.co.uk", AxleAttributes::Format.standardize_url('http://www.infogroup.co.uk') assert_equal "http://www.infogroup.co.uk", AxleAttributes::Format.standardize_url('Http://www.infogroup.co.uk') assert_equal "https://www.infogroup.co.uk", AxleAttributes::Format.standardize_url('https://www.infogroup.co.uk') assert_equal "https://foo.com/xyz/%20yzz", AxleAttributes::Format.standardize_url('https://foo.com/xyz/ yzz') assert_equal "http://infogroup.co.uk", AxleAttributes::Format.standardize_url('infogroup.co.uk') assert_equal "http://infogroup.com", AxleAttributes::Format.standardize_url('INFOGROUP.COM') assert_equal "http://infogroup.com", AxleAttributes::Format.standardize_url('http://infogroup.com ') assert_equal "http://infogroup.com/places/AbC123.html", AxleAttributes::Format.standardize_url('infogroup.com/places/AbC123.html') assert_equal "http://infogroup.com/places/AbC%20123.html", AxleAttributes::Format.standardize_url('infogroup.com/places/AbC 123.html') assert_equal "http://infogroup.com/places/AbC123.html", AxleAttributes::Format.standardize_url('infogroup.com/places/AbC123.html ') assert_equal "http://infogroup.com/places/AbC123.html?ids=47,99#GREATNESS", AxleAttributes::Format.standardize_url('infogroup.com/places/AbC123.html?ids=47,99#GREATNESS') assert_equal "http://infogroup.com:8080/my/photo.png", AxleAttributes::Format.standardize_url('http://infogroup.com:8080/my/photo.png') assert_equal "http://infogroup.com:65535", AxleAttributes::Format.standardize_url('infogroup.com:65535') assert_equal "http://infogroup.com", AxleAttributes::Format.standardize_url('http://infogroup.com/') assert_equal "http://infogroup.com/fun/time/", AxleAttributes::Format.standardize_url('http://infogroup.com/fun/time/') end test "url_regex" do assert "http://infogroup.com".match AxleAttributes::Format.url_regex assert "http://infogroup.com:65535".match AxleAttributes::Format.url_regex end end