Sha256: 2e0bc36f4954c57fa6e9409dee597a9316fedfdaafc75cdd749893cabbb70062

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

require 'rails_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 { is_expected.to set_skip_sidebar_to nil, for: controller }
  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 { is_expected.to set_skip_sidebar_to true, for: controller }
  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, options|
    match do |filter|
      object = options[:for].new
      object.send filter.raw_filter if filter
      @actual = object.instance_variable_get(:@skip_sidebar)
      expect(@actual).to eq expected
    end

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

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
activeadmin_addons-1.1.2 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/resource_controller/sidebars_spec.rb
activeadmin_addons-1.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/resource_controller/sidebars_spec.rb
activeadmin_addons-1.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/resource_controller/sidebars_spec.rb
activeadmin_addons-1.0.1 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/resource_controller/sidebars_spec.rb
activeadmin_addons-1.0.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-a5a53c3f2b8f/spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.12.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.11.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.10.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.9.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.8.pre spec/unit/resource_controller/sidebars_spec.rb
activeadmin-1.0.0.pre2 spec/unit/resource_controller/sidebars_spec.rb
activeadmin-1.0.0.pre1 spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.7.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.6.pre spec/unit/resource_controller/sidebars_spec.rb
yousty-activeadmin-1.0.5.pre spec/unit/resource_controller/sidebars_spec.rb