Sha256: 266de482fdac90edc1dc7297df7dbb9be34310fad8cb1cdadfbe0ccfcf6ab660

Contents?: true

Size: 1.78 KB

Versions: 6

Compression:

Stored size: 1.78 KB

Contents

# encoding: utf-8

RSpec.describe Loaf::ControllerExtensions do

  context 'when classes extend controller_extensions' do
    it { expect(DummyController).to respond_to(:add_breadcrumb) }
    it { expect(DummyController).to respond_to(:breadcrumb) }
    it { expect(DummyController.new).to respond_to(:add_breadcrumb) }
    it { expect(DummyController.new).to respond_to(:breadcrumb) }
    it { expect(DummyController.new).to respond_to(:clear_breadcrumbs) }
  end

  context 'class methods' do
    it 'invokes before_action' do
      allow(DummyController).to receive(:before_action)
      allow(DummyController).to receive(:respond_to?).and_return(true)
      DummyController.breadcrumb('name', 'url_path')
      expect(DummyController).to have_received(:before_action)
    end

    it 'delegates breadcrumb registration to controller instance' do
      name    = 'List objects'
      url     = :object_path
      options = {force: true}
      instance = double(:controller_instance).as_null_object

      allow(DummyController).to receive(:new).and_return(instance)
      DummyController.breadcrumb(name, url, options)
      expect(instance).to have_received(:breadcrumb).with(name, url, options)
    end
  end

  context 'instance methods' do
    it 'instantiates breadcrumbs container' do
      name     = 'List objects'
      url      = :object_path
      instance = DummyController.new

      allow(Loaf::Crumb).to receive(:new)
      instance.breadcrumb(name, url)
      expect(Loaf::Crumb).to have_received(:new).with(name, url, {})
    end

    it 'adds breadcrumb to collection' do
      name     = 'List objects'
      url      = :object_path
      instance = DummyController.new

      expect {
        instance.breadcrumb(name, url)
      }.to change { instance._breadcrumbs.size }.by(1)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
loaf-0.8.1 spec/unit/controller_extensions_spec.rb
loaf-0.8.0 spec/unit/controller_extensions_spec.rb
loaf-0.7.0 spec/unit/controller_extensions_spec.rb
loaf-0.6.2 spec/unit/controller_extensions_spec.rb
loaf-0.6.1 spec/unit/controller_extensions_spec.rb
loaf-0.6.0 spec/unit/controller_extensions_spec.rb