Sha256: 59cf51e87e76ce2fab5f10fc628a24a2db7cf581a464e0140d95e6c13661ee10

Contents?: true

Size: 1.51 KB

Versions: 24

Compression:

Stored size: 1.51 KB

Contents

require "spec_helper"

describe Onebox::Engine::WhitelistedGenericOnebox do

  describe ".===" do
    before do
      described_class.whitelist = %w(eviltrout.com discourse.org)
    end

    it "matches an entire domain" do
      expect(described_class === URI('http://eviltrout.com/resource')).to eq(true)
    end

    it "matches a subdomain" do
      expect(described_class === URI('http://www.eviltrout.com/resource')).to eq(true)
    end

    it "doesn't match a different domain" do
      expect(described_class === URI('http://goodtuna.com/resource')).to eq(false)
    end

    it "doesn't match the period as any character" do
      expect(described_class === URI('http://eviltrouticom/resource')).to eq(false)
    end

    it "doesn't match a prefixed domain" do
      expect(described_class === URI('http://aneviltrout.com/resource')).to eq(false)
    end
  end


  describe 'rewrites' do
    class DummyOnebox < Onebox::Engine::WhitelistedGenericOnebox
      def generic_html
        "<iframe src='https://youtube.com/asdf'></iframe>"
      end
    end

    it "doesn't rewrite URLs that arent in the list" do
      Onebox::Engine::WhitelistedGenericOnebox.rewrites = []
      DummyOnebox.new("http://youtube.com").to_html.should == "<iframe src='https://youtube.com/asdf'></iframe>"
    end

    it "rewrites URLs when whitelisted" do
      Onebox::Engine::WhitelistedGenericOnebox.rewrites = %w(youtube.com)
      DummyOnebox.new("http://youtube.com").to_html.should == "<iframe src='//youtube.com/asdf'></iframe>"
    end
  end


end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
onebox-1.4.3 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.4.2 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.4.1 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.4.0 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.9 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.8 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.7 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.6 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.5 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.4 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.3 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.2 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.1 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.3.0 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.9 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.8 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.7 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.6 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.5 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb
onebox-1.2.4 spec/lib/onebox/engine/whitelisted_generic_onebox_spec.rb