Sha256: 3f87dcc1cf03bee55266f5b25d596d767ccdb42c4e5661951aebc5aab81289e4

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

require 'spec_helper'

module ActiveAdmin
  describe Resource, "Scopes" do

    before { load_defaults! }

    let(:application){ ActiveAdmin::Application.new }
    let(:namespace){ Namespace.new(application, :admin) }

    def config(options = {})
      @config ||= Resource.new(namespace, Category, options)
    end

    describe "adding a scope" do

      it "should add a scope" do
        config.scope :published
        expect(config.scopes.first).to be_a(ActiveAdmin::Scope)
        expect(config.scopes.first.name).to eq "Published"
      end

      it "should retrive a scope by its id" do
        config.scope :published
        expect(config.get_scope_by_id(:published).name).to eq "Published"
      end

      it "should retrieve a string scope with spaces by its id without conflicts" do
        aspace_1 = config.scope "a space"
        aspace_2 = config.scope "as pace"
        expect(config.get_scope_by_id(aspace_1.id).name).to eq "a space"
        expect(config.get_scope_by_id(aspace_2.id).name).to eq "as pace"
      end

      it "should not add a scope with the same name twice" do
        config.scope :published
        config.scope :published
        expect(config.scopes.size).to eq 1
      end

      it "should update a scope with the same id" do
        config.scope :published
        expect(config.scopes.first.scope_block).to be_nil
        config.scope(:published){  }
        expect(config.scopes.first.scope_block).to_not be_nil
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 spec/unit/resource/scopes_spec.rb
activeadministration-0.0.2 spec/unit/resource/scopes_spec.rb
active_administration-0.0.2 spec/unit/resource/scopes_spec.rb
activeadministration-0.0.1 spec/unit/resource/scopes_spec.rb
active_administration-0.0.1 spec/unit/resource/scopes_spec.rb