Sha256: c2f7dc15628d7da98ae19bc4c229445625f486549233d10c726dcb52bc075357

Contents?: true

Size: 1.34 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
walruz-0.0.5 spec/walruz/utils_spec.rb
walruz-0.0.6 spec/walruz/utils_spec.rb