aboutsummaryrefslogtreecommitdiff
blob: 5593c8593e8319cb176625f7d8c1028952842aa0 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
module Permissions
  module TestPermissions
    def cud_allowed( users, testee)
      for user in users
        testee.should be_creatable_by(user)
        testee.should be_updatable_by(user)
        testee.should be_destroyable_by(user)
      end
    end

    def cud_denied( users, testee)
      for user in users
        testee.should_not be_creatable_by(user)
        testee.should_not be_updatable_by(user)
        testee.should_not be_destroyable_by(user)
      end
    end
    
    def ud_allowed( users, testee)
      for user in users
        testee.should be_updatable_by(user)
        testee.should be_destroyable_by(user)
      end
    end

    def ud_denied( users, testee)
      for user in users
        testee.should_not be_updatable_by(user)
        testee.should_not be_destroyable_by(user)
      end
    end

    def view_allowed( users, testee)
      for user in users
        testee.should be_viewable_by(user)
      end
    end
    
    def view_denied( users, testee)
      for user in users
        testee.should_not be_viewable_by(user)
      end
    end

    def edit_allowed( users, testee, field = nil)
      for user in users
        testee.should be_editable_by(user, field)
      end
    end

    def edit_denied( users, testee, field = nil)
      for user in users
        testee.should_not be_editable_by(user, field)
      end
    end

    # if testee is nil it will yield block in for each user in users
    # giving user as paramter to generate testee
    def deny_all(users, testee = nil)
      for user in users
        testee = yield(user) if testee.nil?

        testee.should_not be_creatable_by(user)
        testee.should_not be_destroyable_by(user)
        testee.should_not be_updatable_by(user)
        testee.should_not be_viewable_by(user)
        testee.should_not be_editable_by(user)
      end
    end

    # if testee is nil it will yield block in for each user in users
    # giving user as paramter to generate testee
    def allow_all(users, testee = nil)
      for user in users
        testee = yield(user) if testee.nil?

        testee.should be_creatable_by(user)
        testee.should be_updatable_by(user)
        testee.should be_destroyable_by(user)
        testee.should be_viewable_by(user)
        testee.should be_editable_by(user)
      end
    end
  end
end