Sha256: ed20e7398a6ddee90701946fa9fd1e1003eb822b27e0e4d94e8c8dd4b2f66ad8

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

require 'spec_helper'

describe ActiveAdmin::CanCanAdapter do

  describe "full integration" do

    let(:application){ ActiveAdmin::Application.new }
    let(:namespace){ ActiveAdmin::Namespace.new(application, "Admin") }
    let(:resource){ namespace.register(Post) }

    let :mock_ability_class do
      Class.new do
        include CanCan::Ability

        def initialize(user)
          can :read, Post
          cannot :update, Post
        end

      end
    end

    let(:auth) { namespace.authorization_adapter.new(resource, mock) }

    before do
      namespace.authorization_adapter = ActiveAdmin::CanCanAdapter
      namespace.cancan_ability_class = mock_ability_class
    end

    it "should initialize the ability stored in the namespace configuration" do
      auth.authorized?(:read, Post).should == true
      auth.authorized?(:update, Post).should == false
    end

    it "should scope the collection with accessible_by" do
      collection = mock
      collection.should_receive(:accessible_by).with(auth.cancan_ability, :edit)
      auth.scope_collection(collection, :edit)
    end

  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
activeadmin-0.6.6 spec/unit/cancan_adapter_spec.rb
activeadmin-0.6.5 spec/unit/cancan_adapter_spec.rb
activeadmin-0.6.4 spec/unit/cancan_adapter_spec.rb
activeadmin-0.6.3 spec/unit/cancan_adapter_spec.rb
activeadmin-0.6.2 spec/unit/cancan_adapter_spec.rb
activeadmin-0.6.1 spec/unit/cancan_adapter_spec.rb
aa-rails4-0.6.0 spec/unit/cancan_adapter_spec.rb