Sha256: 546f88aba3f96116e0ac906f76699571c9fd43a3b3e9232d5c04acbf3fa6e363

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helpers/boot'

describe Protector::CanCan::Ability do
  let(:_Model) do
    Class.new(ActiveRecord::Base) do
      self.table_name = 'dummies'
    end
  end

  let(:_Ability) do
    Class.new do
      include CanCan::Ability
    end
  end

  it "defaults properly" do
    _Ability.new.protector_subject?.should == false
  end

  it "initializes properly" do
    _Ability.class_eval do
      def initialize(user)
        import_protector user
      end
    end

    ability = _Ability.new('user')

    ability.protector_subject?.should == true
    ability.protector_subject.should == 'user'
    ability.can?(:read, _Model).should == false
    ability.can?(:create, _Model).should == false
    ability.can?(:update, _Model).should == false
    ability.can?(:destroy, _Model).should == false
  end

  it "proxies rules" do
    _Ability.class_eval do
      def initialize(user)
        import_protector user
      end
    end

    _Model.class_eval do
      protect do |user|
        can :view
        can :create
        can :update
        can :destroy
        can :test
      end
    end

    ability = _Ability.new('user')

    ability.protector_subject?.should == true
    ability.protector_subject.should == 'user'
    ability.can?(:read, _Model).should == true
    ability.can?(:create, _Model).should == true
    ability.can?(:update, _Model).should == true
    ability.can?(:destroy, _Model).should == true
    ability.can?(:test, _Model).should == true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
protector-cancan-0.1.1 spec/lib/protector/cancan/ability_spec.rb
protector-cancan-0.1.0 spec/lib/protector/cancan/ability_spec.rb