Sha256: f507b4ec87edab0deee8c8f61e1e209c4538d2ad22ae430dd8e7261dd2291f29

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'spec_helper'

describe Loaf::ControllerExtensions do

  class Controller
    def self.helper_method(*args); end
    include Loaf::ControllerExtensions
  end

  let(:name) { stub }
  let(:url) { stub }
  let(:options) { stub }

  context 'classes extending controller_extensions' do
    subject { Controller }
    specify { should respond_to(:add_breadcrumb) }
    specify { subject.new.should respond_to(:add_breadcrumb) }
    specify { subject.new.should respond_to(:add_breadcrumbs) }
    specify { subject.new.should respond_to(:clear_breadcrumbs) }
  end

  context 'class methods' do
    let(:controller) { Controller }
    let(:instance) { Class.new(Controller) }

    it 'invokes before_filter' do
      controller.should_receive(:before_filter)
      controller.add_breadcrumb('name', 'url_path')
    end

    it 'delegates to instance' do
      controller.stub(:before_filter).and_yield instance
      instance.should_receive(:send).with(:add_breadcrumb, name, url, options)
      controller.add_breadcrumb(name, url, options)
    end
  end

  context 'instance methods' do
    let(:controller) { Controller }
    let(:instance) { Controller.new }

    it 'instantiates breadcrumbs container' do
      Loaf::Crumb.should_receive(:new).with(name, url)
      instance.add_breadcrumb(name,url)
    end

    it 'adds breadcrumb to collection' do
      expect do
        instance.add_breadcrumb(name, url)
      end.to change { instance._breadcrumbs.size }.by(1)
    end
  end
end # Loaf::ControllerExtensions

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
loaf-0.2.1 spec/loaf/controller_extensions_spec.rb