Sha256: 594bd3703f45940dfd8e9756936660688ac03fa24ec1d350ce5b2e29f2e6ee22

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

require 'spec_helper'

class FooController < ActionController::Base
  include Rafters::ComponentContext
end

class FooComponent
  include Rafters::Component
end

describe Rafters::ComponentContext do
  let(:controller) { FooController.new }
  let(:renderer) { double("ComponentRenderer", render: "<p>Output</p>") }

  before do
    Rafters::ComponentRenderer.stub(:new).and_return(renderer)
  end

  describe "#render_component" do
    it "renders the provided component" do
      renderer.should_receive(:render).with(instance_of(FooComponent), nil)
      controller.render_component(:foo)
    end

    context "with settings" do
      it "renders the provided component with the given settings" do
        FooComponent.should_receive(:new).with({ test: true })
        controller.render_component(:foo, test: true)
      end
    end

    context "with a specified template name" do
      it "renders the provided component using the given template name" do
        renderer.should_receive(:render).with(instance_of(FooComponent), "template_name")
        controller.render_component(:foo, {}, "template_name")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rafters-0.2.0 spec/rafters/component_context_spec.rb
rafters-0.1.3 spec/rafters/component_context_spec.rb
rafters-0.1.2 spec/rafters/component_context_spec.rb
rafters-0.1.1 spec/rafters/component_context_spec.rb
rafters-0.1.0 spec/rafters/component_context_spec.rb
rafters-0.0.5 spec/rafters/component_context_spec.rb