Sha256: 84b3b2e6cf0e5b249aa26c41dc2a538a95cb3fe34dd72d1a3775ade991441a04

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

require 'spec_helper'

describe ActiveAdmin::AuthorizationAdapter do

  let(:adapter) { ActiveAdmin::AuthorizationAdapter.new(double, double) }

  describe "#authorized?" do

    it "should always return true" do
      expect(adapter.authorized?(:read, "Resource")).to be_true
    end

  end

  describe "#scope_collection" do

    it "should return the collection unscoped" do
      collection = double
      expect(adapter.scope_collection(collection, ActiveAdmin::Auth::READ)).to eq collection
    end

  end

  describe "using #normalized in a subclass" do

    let(:auth_class) do
      Class.new(ActiveAdmin::AuthorizationAdapter) do

        def authorized?(action, subject = nil)
          case subject
          when normalized(String)
            true
          else
            false
          end
        end

      end
    end

    let(:adapter) { auth_class.new(double, double) }

    it "should match against a class" do
      expect(adapter.authorized?(:read, String)).to be_true
    end

    it 'should match against an instance' do
      expect(adapter.authorized?(:read, "String")).to be_true
    end

    it 'should not match a different class' do
      expect(adapter.authorized?(:read, Hash)).to be_false
    end

    it 'should not match a different instance' do
      expect(adapter.authorized?(:read, {})).to be_false
    end

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
active_administration-0.0.3 spec/unit/authorization/authorization_adapter_spec.rb
activeadministration-0.0.2 spec/unit/authorization/authorization_adapter_spec.rb
active_administration-0.0.2 spec/unit/authorization/authorization_adapter_spec.rb
activeadministration-0.0.1 spec/unit/authorization/authorization_adapter_spec.rb
active_administration-0.0.1 spec/unit/authorization/authorization_adapter_spec.rb