Skip to content

Instantly share code, notes, and snippets.

@jbgutierrez
Created November 28, 2010 13:34
Show Gist options
  • Select an option

  • Save jbgutierrez/718934 to your computer and use it in GitHub Desktop.

Select an option

Save jbgutierrez/718934 to your computer and use it in GitHub Desktop.
video_test.rb
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&params
}
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