Sha256: 4a5b7eaa47b54abed8a677bccb690268d113aeecdbfe164274036352a9d77934

Contents?: true

Size: 1.39 KB

Versions: 19

Compression:

Stored size: 1.39 KB

Contents

require 'rails_helper'

RSpec.describe ActiveAdmin::MenuCollection do

  let(:menus) { ActiveAdmin::MenuCollection.new }

  describe "#add" do

    it "should initialize a new menu when first item" do
      menus.add :default, label: "Hello World"

      expect(menus.fetch(:default).items.size).to eq 1
      expect(menus.fetch(:default)["Hello World"]).to be_an_instance_of(ActiveAdmin::MenuItem)
    end

    it "should add items to an existing menu" do
      menus.add :default, label: "Hello World"
      menus.add :default, label: "Hello World Again"

      expect(menus.fetch(:default).items.size).to eq 2
    end

  end

  describe "#clear!" do

    it "should remove all menus" do
      menus.add :default, label: "Hello World"

      menus.clear!

      expect {
        menus.fetch(:non_default_menu)
      }.to raise_error(ActiveAdmin::NoMenuError)

    end

  end

  describe "#on_build" do

    it "runs a callback when fetching a menu" do
      menus.on_build do |m|
        m.add :default, label: "Hello World"
      end

      expect(menus.fetch(:default)["Hello World"]).to_not eq nil
    end

    it "re-runs the callbacks when the menu is cleared" do
      menus.on_build do |m|
        m.add :default, label: "Hello World"
      end

      expect(menus.fetch(:default)["Hello World"]).to_not eq nil
      menus.clear!
      expect(menus.fetch(:default)["Hello World"]).to_not eq nil
    end

  end

end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
activeadmin-rb-1.6.0 spec/unit/menu_collection_spec.rb
activeadmin-rb-1.5.2 spec/unit/menu_collection_spec.rb
activeadmin-rb-1.5.1 spec/unit/menu_collection_spec.rb
activeadmin-rb-1.5.0 spec/unit/menu_collection_spec.rb
activeadmin_addons-1.7.1 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin-rb-1.4.0 spec/unit/menu_collection_spec.rb
activeadmin_addons-1.7.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin-1.3.1 spec/unit/menu_collection_spec.rb
activeadmin_addons-1.6.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin_addons-1.5.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin-1.3.0 spec/unit/menu_collection_spec.rb
activeadmin_addons-1.4.0 vendor/bundle/ruby/2.2.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin_addons-1.3.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin_addons-1.2.0 vendor/bundle/ruby/2.3.0/bundler/gems/activeadmin-f71b375325eb/spec/unit/menu_collection_spec.rb
activeadmin-1.2.1 spec/unit/menu_collection_spec.rb
activeadmin-1.2.0 spec/unit/menu_collection_spec.rb
activeadmin-1.1.0 spec/unit/menu_collection_spec.rb
activeadmin-1.0.0 spec/unit/menu_collection_spec.rb
activeadmin-1.0.0.pre5 spec/unit/menu_collection_spec.rb