Created
July 7, 2011 09:57
-
-
Save boyvanamstel/1069215 to your computer and use it in GitHub Desktop.
Test::Unit test for valid url and implementation of valid url testing in Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test in test/functional/sites_controller_test.rb | |
test "should contain a valid url" do | |
@site.url = "random text" | |
assert @site.invalid? | |
end | |
# Implementation in app/models/site.rb | |
class Site < ActiveRecord::Base | |
validates_format_of :url, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment