Sha256: 28fc21218afd8e8afe9e5ad57493e18636f45cf36ddf28844cee26040eb12aca

Contents?: true

Size: 1.26 KB

Versions: 3

Compression:

Stored size: 1.26 KB

Contents

require 'spec_helper'

describe Rafters::ComponentRenderer do
  let(:view_context) { double("ViewContext", render: "<p>Output</p>") }
  let(:controller) { double("Controller", prepend_view_path: true, view_context: view_context) }

  describe "when initialized" do
    before do
      Rafters.stub(:view_paths).and_return(["/path/to/views"])
    end

    it "should add the view paths for all components to the controller" do
      controller.should_receive(:prepend_view_path).with("/path/to/views")
      Rafters::ComponentRenderer.new(controller)
    end
  end

  describe "#render" do
    subject { Rafters::ComponentRenderer.new(controller) }

    let(:component) do
      double("Component", attributes: { title: "Foo" }, :'controller=' => true, template_name: "template")
    end

    it "renders the component template with it's settings and attributes" do
      view_context.should_receive(:render).with(file: "/template", locals: { title: "Foo" })
      subject.render(component)
    end

    context "with a specified template name" do
      it "renders the component with the specified template" do
        view_context.should_receive(:render).with(file: "/custom_template", locals: { title: "Foo" })
        subject.render(component, "custom_template")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rafters-0.0.5 spec/rafters/component_renderer_spec.rb
rafters-0.0.4 spec/rafters/component_renderer_spec.rb
rafters-0.0.3 spec/rafters/component_renderer_spec.rb