cch1 / authorize

A mature Rails Plugin for role-based authorization (polymorphic on subject and trustee, DSL for auth expressions, model- and controller-level expressions)

This URL has Read+Write access

authorize / test / trustee_test.rb
100644 49 lines (38 sloc) 1.45 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require File.dirname(__FILE__) + '/test_helper.rb'
 
class TrusteeTest < ActiveSupport::TestCase
  fixtures :users, :widgets, :authorizations
 
  test 'should identify permissions' do
    assert ps = users(:chris).permissions
    assert_equal 2, ps.size
    assert ps.any?{|p| p.subject == widgets(:foo) }
  end
  
  test 'should know it is authorized' do
    assert users(:chris).authorized?('owner', widgets(:foo))
  end
 
  test 'should know it is not authorized' do
    assert !users(:chris).authorized?('owner', widgets(:bar))
    assert !users(:chris).authorized?('doorman', widgets(:foo))
  end
 
  test 'should be authorizable' do
    users(:chris).authorize('owner',widgets(:bar))
    assert users(:chris).authorized?('owner', widgets(:bar))
  end
 
  test 'should be unauthorizable' do
    users(:chris).unauthorize('owner', widgets(:foo))
    assert !users(:chris).authorized?('owner', widgets(:foo))
  end
 
  test 'should know it is not authorized over a class' do
    assert !users(:chris).authorized?('owner', Widget)
  end
 
  test 'should be authorizable over a class' do
    users(:chris).authorize('master', Widget)
    assert users(:chris).authorized?('master', Widget)
  end
 
  test 'should know it is authorized generically' do
    assert users(:chris).authorized?('overlord')
  end
 
  test 'should be unauthorizable generically' do
    users(:chris).unauthorize('overlord')
    assert !users(:chris).authorized?('overlord')
  end
end