Created
November 28, 2010 13:34
-
-
Save jbgutierrez/718934 to your computer and use it in GitHub Desktop.
video_test.rb
This file contains hidden or 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
| require 'test_helper' | |
| class VideoTest < ActiveSupport::TestCase | |
| test "should accept only valid urls" do | |
| video = Video.new | |
| assert(video.invalid?) # blank urls are not accepted | |
| invalid_urls = # valid but not accepted | |
| %w{ | |
| http://youtu.be/IN7O3pnvT6Q?hd=1 | |
| http://youtu.be/IN7O3pnvT6Q | |
| } | |
| invalid_urls += # not valid and not accepted | |
| %w{ | |
| http://www.youtube.com/v/with_a_long_hash | |
| } | |
| invalid_urls.each do |url| | |
| video.url = url | |
| assert(video.invalid?) | |
| end | |
| valid_urls = # valid and accepted | |
| %w{ | |
| http://www.youtube.com/v/IN7O3pnvT6Q | |
| http://www.youtube.com/watch?v=IN7O3pnvT6Q | |
| http://www.youtube.com/watch?v=IN7O3pnvT6Q&hd=1 | |
| http://www.youtube.com/watch?hd=1&v=IN7O3pnvT6Q | |
| http://www.youtube.com/watch?hd=1&v=IN7O3pnvT6Q&feature=topvideos | |
| } | |
| valid_urls += # not valid but accepted | |
| %w{ | |
| mistyped_urlv/IN7O3pnvT6Q?params | |
| mistyped_urlv=IN7O3pnvT6Q¶ms | |
| } | |
| valid_urls.each do |url| | |
| video.url = url | |
| assert(video.valid?) | |
| video.save | |
| assert_equal("http://www.youtube.com/v/IN7O3pnvT6Q", video.url) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment