Sha256: 88333521a583dc5205565e1ccb6b719d3665e025181ce42b7e68feb3c4567d02

Contents?: true

Size: 1.58 KB

Versions: 26

Compression:

Stored size: 1.58 KB

Contents

require "spec_helper"

describe Onebox do

  before do
    fake("http://www.amazon.com", response("amazon"))
  end

  describe ".preview" do
    let(:url) { "http://www.amazon.com/product" }
    it "creates a cache that responds as expected" do
      preview = Onebox.preview(url)
      cache = preview.cache
      expect(cache).to respond_to(:key?, :store, :fetch)
    end

    it "stores the value in cache if it doesn't exist" do
      preview = Onebox.preview(url)
      preview.to_s
      cache = preview.cache
      expect(cache.key?(url)).to eq(true)
    end

    it "replaces the cache if the cache is expired" do
      preview = Onebox.preview(url, cache: Moneta.new(:Memory, expires: 100_000, serializer: :json))
      cache = preview.cache
      expect(cache.fetch(url)).to be(nil)
    end
  end

  describe "templates" do
    let(:ignored)  { ["templates/_layout.mustache"] }
    let(:templates) { Dir["templates/*.mustache"] - ignored }

    def expect_templates_to_not_match(text)
      templates.each do |template|
        expect(File.read(template)).not_to match(text)
      end
    end

    it "should not contain any script tags" do
      expect_templates_to_not_match(/<script/)
    end
  end

  describe 'has_matcher?' do
    before do
      Onebox::Engine::WhitelistedGenericOnebox.whitelist = %w(youtube.com)
    end
    it "has no matcher for a made up url" do
      expect(Onebox.has_matcher?("http://wow.com/omg/doge")).to be false
    end

    it "has a matcher for a real site" do
      expect(Onebox.has_matcher?("http://www.youtube.com/watch?v=azaIE6QSMUs")).to be true
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
onebox-1.5.43 spec/lib/onebox_spec.rb
onebox-1.5.42 spec/lib/onebox_spec.rb
onebox-1.5.41 spec/lib/onebox_spec.rb
onebox-1.5.40 spec/lib/onebox_spec.rb
onebox-1.5.39 spec/lib/onebox_spec.rb
onebox-1.5.38 spec/lib/onebox_spec.rb
onebox-1.5.37 spec/lib/onebox_spec.rb
onebox-1.5.36 spec/lib/onebox_spec.rb
onebox-1.5.35 spec/lib/onebox_spec.rb
onebox-1.5.34 spec/lib/onebox_spec.rb
onebox-1.5.33 spec/lib/onebox_spec.rb
onebox-1.5.32 spec/lib/onebox_spec.rb
onebox-1.5.31 spec/lib/onebox_spec.rb
onebox-1.5.30 spec/lib/onebox_spec.rb
onebox-1.5.29 spec/lib/onebox_spec.rb
onebox-1.5.28 spec/lib/onebox_spec.rb
onebox-1.5.27 spec/lib/onebox_spec.rb
onebox-1.5.26 spec/lib/onebox_spec.rb
onebox-1.5.25 spec/lib/onebox_spec.rb
onebox-1.5.24 spec/lib/onebox_spec.rb