require 'spec_helper' describe Onebox::Engine::YoutubeOnebox do before do fake("http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube")) fake("https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ", response("youtube-channel")) end it "adds wmode=opaque" do Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo') .to_s.should match(/wmode=opaque/) end it "rewrites URLs for videos to be HTTPS" do # match: plain HTTP and protocol agnostic regex = /(http:|["']\/\/)/ Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo') .to_s.should_not match(regex) Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo') .placeholder_html.should_not match(regex) Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ') .to_s.should_not match(regex) end it "can onebox a channel page" do Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ') .to_s.should match(/Google Chrome/) end it "can onebox a playlist" do pending('no opengraph on playlists, needs special handling') Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s end it "does not make HTTP requests unless necessary" do # We haven't defined any fixture for requests associated with this ID, so if # any HTTP requests are made fakeweb will complain and the test will fail. Onebox.preview('http://www.youtube.com/watch?v=q39Ce3zDScI').to_s end it "does not fail if we cannot get the video ID from the URL" do # TODO this test no longer makes sense - the video ID is successfully retrieved and no fakeweb request is made Onebox.preview('http://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo') .to_s.should match(/embed/) end it "returns an image as the placeholder" do Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo') .placeholder_html.should match(/