Sha256: b7b92708bce26c4768e418e3fbe93333ea4c5d535d60ef9de9456a431f225205

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

require 'rspec'
require 'cantango'
# require 'simple_roles'
require 'fixtures/models'
require 'cantango/rspec'

def config_folder
  File.dirname(__FILE__)+ "/../fixtures/config/"
end

CanTango.configure do |config|
  config.clear!
end
# CanTango.debug!

class User
  tango_user
  include_and_extend SimpleRoles
end

class AdminRolePermit < CanTango::RolePermit
  def initialize ability
    super
  end

  protected

  def static_rules
    can :read, Article
  end

  module Cached
    def permit_rules
      can :edit, Article
      can :delete, Article
    end
  end
end

module CanTango
  class CachedAbility
    def permit_rules
      can :read, Post
    end
  end
end

describe CanTango::AbilityExecutor do
  context 'cached only' do
    before do
      CanTango.configure.ability.mode = :cache

      @user = User.new 'admin', 'admin@mail.ru', :role => 'admin'
      @abil = CanTango::AbilityExecutor.new @user
    end

    subject { CanTango::AbilityExecutor.new @user }

    describe 'config cache' do
      specify { CanTango.configure.ability.modes.should == [:cache] }
    end

    describe 'engines_on?' do
      specify { subject.engines_on?.should be_true }
    end

    its(:cached_rules)      { should_not be_empty }
    its(:non_cached_rules)  { should be_empty }

    describe 'rules contain only non-cached rules' do
      specify { subject.rules.size.should == @abil.cached_rules.size }
      specify { subject.rules.size.should == 4 }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.9.3.2 spec/cantango/ability_executor/cached_only_spec.rb