Sha256: 2c454e93686d779f39b88d818d87dfb3582cea10217f370a43b0eab84a0f7760

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'rspec'
require 'cantango'
require 'fixtures/models'

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

  protected

  def dynamic_rules
    can(:read, Post) if $test == true
  end
end

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

  protected

  def static_rules
  end
  def dynamic_rules
    can(:read, Article) do |article|
      $test == true
    end
  end
end

describe CanTango::PermitEngine::RolePermit do
  let (:user) do
    User.new 'kris'
  end
  let (:user_account) do
    ua = UserAccount.new user, :roles => [:admin, :user], :role_groups => []
    user.account = ua
  end
  let (:ability) do
    CanTango::Ability.new user_account
  end
  let (:permit) do
    AdminRolePermit.new ability
  end
  before(:each) do
    CanTango.configure do |config|
      config.permits.set :on
      config.permissions.set :off
    end
  end

  describe 'Having some dynamic conditions based on global things' do
    it "shoud react if global thing changed" do
      pending
      $test = true
      ability.can?(:read, Article.new).should == true
      $test = false
      ability.can?(:read, Article.new).should == false
    end
  end
  
  describe 'Having some dynamic conditions based on global things' do
    it "shoud react if global thing changed" do
      pending "Need to reveal CanCan's situation and caching"
      #$test = true
      #ability.can?(:read, Post.new).should == true
      #$test = false
      #ability.can?(:read, Post.new).should == false
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 spec/cantango/permit_engine/permit/permit_static_and_dynamic_rules_spec.rb