Sha256: fcf034ceeb7b44c55fe650639bdf7a95fc6f7bcfe88fd737adde9e5cd7db1184

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe ActiveAdmin::ResourceController::Sidebars do
  let(:controller){ Admin::PostsController }

  context 'without before_filter' do
    before do
      ActiveAdmin.register Post
    end

    subject { find_before_filter controller, :skip_sidebar! }

    it {should set_skip_sidebar_to nil}
  end

  describe '#skip_sidebar!' do
    before do
      ActiveAdmin.register Post do
        before_filter :skip_sidebar!
      end
    end

    subject { find_before_filter controller, :skip_sidebar! }

    it { should set_skip_sidebar_to true }
  end

  def find_before_filter(controller, filter)
    #raise controller._process_action_callbacks.map(&:filter).inspect
    controller._process_action_callbacks.detect { |f| f.raw_filter == filter.to_sym }
  end

  RSpec::Matchers.define :set_skip_sidebar_to do |expected|
    match do |filter|
      klass = filter && filter.klass || controller
      object = klass.new
      object.send filter.raw_filter if filter
      @actual = object.instance_variable_get(:@skip_sidebar)
      expect(@actual).to eq expected
    end

    failure_message_for_should do |filter|
      message = "expected before_filter to set @skip_sidebar to '#{expected}', but was '#{@actual}'"
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 spec/unit/resource_controller/sidebars_spec.rb
activeadministration-0.0.2 spec/unit/resource_controller/sidebars_spec.rb
active_administration-0.0.2 spec/unit/resource_controller/sidebars_spec.rb
activeadministration-0.0.1 spec/unit/resource_controller/sidebars_spec.rb
active_administration-0.0.1 spec/unit/resource_controller/sidebars_spec.rb