Sha256: 01b50473b29df4fd2ceab40f27258798135534d92c8c0f0e0e5d881d4f1a5c89

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 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 :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, double) }

    before do
      namespace.authorization_adapter = ActiveAdmin::CanCanAdapter
      namespace.cancan_ability_class = 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 = double
      collection.should_receive(:accessible_by).with(auth.cancan_ability, :edit)
      auth.scope_collection(collection, :edit)
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yousty-activeadmin-1.0.4.pre spec/unit/cancan_adapter_spec.rb
yousty-activeadmin-1.0.3.pre spec/unit/cancan_adapter_spec.rb
yousty-activeadmin-1.0.2.pre spec/unit/cancan_adapter_spec.rb
yousty-activeadmin-1.0.1.pre spec/unit/cancan_adapter_spec.rb
yousty-activeadmin-1.0.0.pre spec/unit/cancan_adapter_spec.rb