Sha256: a634a3d8ce7aef73a493e4eeca0679d85a386757a5c4f2fff0c61783a5cc2b4c

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require File.dirname(__FILE__) + '/../spec_helper'

describe Walruz::Utils do
  
  def check_actor_can_on_subject(label, actor, subject)
    lambda do
      actor.authorize(label, subject)
    end.should_not raise_error(Walruz::NotAuthorized)
  end
  
  def check_actor_can_not_on_subject(label, actor, subject)
    lambda do
      actor.authorize(label, subject)
    end.should raise_error(Walruz::NotAuthorized)
  end
  
  describe "when using combinators `any`, `all` or `negate`" do
    
    it "should work properly" do
      check_actor_can_not_on_subject(:sell, Beatle::JOHN, Song::A_DAY_IN_LIFE)
      check_actor_can_on_subject(:sell, Beatle::JOHN, Song::ALL_YOU_NEED_IS_LOVE)
    end
    
  end
  
  describe "#all" do

    it "should return as policy keyword, the name of the original policies keywords concatenated with `_and_`" do
      Beatle::JOHN.can?(:sell, Song::ALL_YOU_NEED_IS_LOVE) do |policy_params|
        policy_params[:"author_policy_and_not(author_in_colaboration_policy)?"].should be_true
      end
    end
    
  end
  
  describe "#negate" do
    
    it "should return as policy keyword, the name of the original policy keyword with a `not()` around" do
      Beatle::JOHN.can?(:sell, Song::ALL_YOU_NEED_IS_LOVE) do |policy_params|
        policy_params[:"not(author_in_colaboration_policy)?"].should be_true
      end
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
walruz-0.0.4 spec/walruz/utils_spec.rb