Sha256: 85c76d61ac8b242a6c49ae609ca02b00694a53dad83b58ee545e7877590f87ba

Contents?: true

Size: 1.93 KB

Versions: 45

Compression:

Stored size: 1.93 KB

Contents

require "spec_helper"

describe Onebox::Layout do
  let(:cache) { Moneta.new(:Memory, expires: true, serializer: :json) }
  let(:record) { {} }
  let(:onebox) { described_class.new("amazon", record, cache) }
  let(:html) { onebox.to_html }

  describe ".template_path" do
    let(:template_path) { onebox.template_path }

    before(:each) do
      Onebox.options.load_paths << "directory_a"
      Onebox.options.load_paths << "directory_b"
    end

    context "when template exists in directory_b" do
      before(:each) do
        allow_any_instance_of(described_class).to receive(:template?) do |path|
          path == "directory_b"
        end
      end

      it "returns directory_b" do
        expect(template_path).to eq("directory_b")
      end
    end

    context "when template exists in directory_a" do
      before(:each) do
        allow_any_instance_of(described_class).to receive(:template?) do |path|
          path == "directory_a"
        end
      end

      it "returns directory_a" do
        expect(template_path).to eq("directory_a")
      end
    end

    context "when template doesn't exist in directory_a or directory_b" do
      it "returns default path" do
        expect(template_path).to include("template")
      end
    end

    after(:each) do
      Onebox.options.load_paths.pop(2)
    end
  end

  describe "#to_html" do
    class OneboxEngineLayout
      include Onebox::Engine

      def data
        "new content"
      end
    end

    it "reads from cache if rendered template is cached" do
      described_class.new("amazon", record, cache).to_html
      expect(cache).to receive(:fetch)
      described_class.new("amazon", record, cache).to_html
    end

    it "contains layout template" do
      expect(html).to include(%|class="onebox|)
    end

    it "contains the view" do
      record = { link: "foo" }
      html = described_class.new("amazon", record, cache).to_html
      expect(html).to include(%|"foo"|)
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

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