require 'spec_helper' describe Onebox::Engine::YoutubeOnebox do before do fake("https://www.youtube.com/watch?feature=player_embedded&v=21Lk4YiASMo", response("youtube")) fake("https://youtu.be/21Lk4YiASMo", response("youtube")) fake("https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ", response("youtube-channel")) fake("https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-playlist")) fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/watch?v=21Lk4YiASMo", response("youtube-json")) fake("https://www.youtube.com/oembed?format=json&url=https://www.youtube.com/playlist?list=PL5308B2E5749D1696", response("youtube-list-json")) end it "adds wmode=opaque" do expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).to match(/wmode=opaque/) end it "rewrites URLs for videos to be HTTPS" do # match: plain HTTP and protocol agnostic regex = /(http:|["']\/\/)/ expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').to_s).not_to match(regex) expect(Onebox.preview('https://www.youtube.com/watch?v=21Lk4YiASMo').placeholder_html).not_to match(regex) expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).not_to match(regex) end it "can onebox a channel page" do expect(Onebox.preview('https://www.youtube.com/channel/UCL8ZULXASCc1I_oaOT0NaOQ').to_s).to match(/Google Chrome/) end it "can onebox a playlist" do expect(Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').to_s).to match(/iframe/) placeholder_html = Onebox.preview('https://www.youtube.com/playlist?list=PL5308B2E5749D1696').placeholder_html expect(placeholder_html).to match(/