Sha256: 89acbd60befe54fc9e5e826da4f75f3f9d078cd1d1ec75c0884428eb7a497921

Contents?: true

Size: 1.34 KB

Versions: 21

Compression:

Stored size: 1.34 KB

Contents

require 'rails_helper'

RSpec.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 eq 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 eq true
    end

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

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

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

  end

end

Version data entries

21 entries across 21 versions & 4 rubygems

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