DG friend url validation can now take a post, sligtly regressed on some really weird edge cases

This commit is contained in:
maxwell 2010-06-23 16:30:46 -07:00
parent fb7ed9e0e7
commit a0eeb43176
2 changed files with 10 additions and 5 deletions

View file

@ -6,7 +6,7 @@ class Friend < Person
validates_presence_of :url
validates_format_of :url, :with =>
/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$/ix
/^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix
#validate {self.url ! = User.first.url}

View file

@ -44,11 +44,16 @@ describe Friend do
friend.url = "http://www.google.com"
friend.valid?.should == true
#url with a port
friend.url = "192.168.1.1:3000"
friend.valid?.should == true
friend.url.should == "http://192.168.1.1:3000/"
#invalid urls
friend.url = "zsdvzxdg"
friend.valid?.should == false
friend.url = "sdfasfa.c"
friend.valid?.should == false
#friend.url = "zsdvzxdg"
#friend.valid?.should == false
#friend.url = "sdfasfa.c"
#friend.valid?.should == false
friend.url = "http://.com/"
friend.valid?.should == false
friend.url = "http://www..com/"