require File.expand_path('spec/spec_helper')
describe UrlToMediaTag do
it "has a VERSION" do
UrlToMediaTag::VERSION.should =~ /^\d+\.\d+\.\d+$/
end
describe 'convert' do
it "converts youtube" do
expected = ""
UrlToMediaTag.convert('http://www.youtube.com/watch?v=kW-dS4otEZU').should == expected
end
it "converts vimeo" do
expected = ""
UrlToMediaTag.convert('http://vimeo.com/26881896').should == expected
end
it "converts images" do
UrlToMediaTag.convert('http://foo.com/foo.jpg').should == ""
UrlToMediaTag.convert('http://foo.com/foo.gif').should == ""
UrlToMediaTag.convert('http://foo.com/foo.png').should == ""
UrlToMediaTag.convert('http://foo.com/foo.jpeg').should == ""
UrlToMediaTag.convert('http://foo.com/foo.JPG').should == ""
end
it "converts images with ?" do
UrlToMediaTag.convert('http://foo.com/foo.jpg?foo=bar').should == ""
end
it "does not convert unknown" do
UrlToMediaTag.convert('xxx').should == nil
end
it "marks output as html_safe" do
UrlToMediaTag.convert('http://vimeo.com/26881896').html_safe?.should == true
end
it "prevents xss" do
UrlToMediaTag.convert('http://vimeo.com/26881896<').should == nil
UrlToMediaTag.convert('http://vimeo.com/26881896>').should == nil
end
describe 'settings' do
it "uses directly given settings" do
UrlToMediaTag.convert('http://foo.com/foo.jpg', :foo => 'bar').should == ""
end
it "uses indirectly given settings" do
UrlToMediaTag.convert('http://foo.com/foo.jpg', :settings => {:image => {:foo => 'bar'}}).should == ""
end
it "does not use not-matching settings" do
UrlToMediaTag.convert('http://foo.com/foo.jpg', :settings => {:video => {:foo => 'bar'}}).should == ""
end
it "users more precise settings" do
UrlToMediaTag.convert('http://vimeo.com/26881896', :settings => {:video => {:foo => 'bar'}, :vimeo => {:foo => 'baz'}}).should include('foo="baz"')
end
it "overwrites default settings" do
UrlToMediaTag.convert('http://foo.com/foo.jpg', :foo => 'bar', :settings => {:image => {:foo => 'baz'}}).should include('foo="baz"')
end
it "can take options from settings" do
UrlToMediaTag.convert('http://vimeo.com/26881896').should include('title=0')
UrlToMediaTag.convert('http://vimeo.com/26881896', :settings => {:vimeo => {:show_title => true}}).should_not include('title=0')
end
end
end
end