canable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/canable.rb +3 -3
- data/test/test_enforcers.rb +13 -0
- metadata +21 -11
- data/.gitignore +0 -22
data/lib/canable.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Canable
|
2
|
-
Version = '0.
|
2
|
+
Version = '0.2.0'
|
3
3
|
|
4
4
|
# Module that holds all the can_action? methods.
|
5
5
|
module Cans; end
|
@@ -70,8 +70,8 @@ module Canable
|
|
70
70
|
current_user.can_#{can}?(resource)
|
71
71
|
end
|
72
72
|
|
73
|
-
def enforce_#{can}_permission(resource)
|
74
|
-
raise
|
73
|
+
def enforce_#{can}_permission(resource, message="")
|
74
|
+
raise(Canable::Transgression, message) unless can_#{can}?(resource)
|
75
75
|
end
|
76
76
|
private :enforce_#{can}_permission
|
77
77
|
EOM
|
data/test/test_enforcers.rb
CHANGED
@@ -20,6 +20,10 @@ class EnforcersTest < Test::Unit::TestCase
|
|
20
20
|
def update
|
21
21
|
enforce_update_permission(article)
|
22
22
|
end
|
23
|
+
|
24
|
+
def edit
|
25
|
+
enforce_update_permission(article, "You Can't Edit This")
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
@article = mock('article')
|
@@ -43,5 +47,14 @@ class EnforcersTest < Test::Unit::TestCase
|
|
43
47
|
@controller.current_user = nil
|
44
48
|
assert_raises(Canable::Transgression) { @controller.update }
|
45
49
|
end
|
50
|
+
|
51
|
+
should "pass message around the stack" do
|
52
|
+
@controller.current_user = nil
|
53
|
+
begin
|
54
|
+
@controller.edit
|
55
|
+
rescue Canable::Transgression => e
|
56
|
+
assert_equal e.message, "You Can't Edit This"
|
57
|
+
end
|
58
|
+
end
|
46
59
|
end
|
47
60
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Nunemaker
|
@@ -14,16 +15,17 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date:
|
18
|
-
default_executable:
|
18
|
+
date: 2011-06-30 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ~>
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 35
|
27
29
|
segments:
|
28
30
|
- 2
|
29
31
|
- 10
|
@@ -35,9 +37,11 @@ dependencies:
|
|
35
37
|
name: mocha
|
36
38
|
prerelease: false
|
37
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
38
41
|
requirements:
|
39
42
|
- - ~>
|
40
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 43
|
41
45
|
segments:
|
42
46
|
- 0
|
43
47
|
- 9
|
@@ -49,9 +53,11 @@ dependencies:
|
|
49
53
|
name: mongo_mapper
|
50
54
|
prerelease: false
|
51
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
52
57
|
requirements:
|
53
58
|
- - ">="
|
54
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
55
61
|
segments:
|
56
62
|
- 0
|
57
63
|
version: "0"
|
@@ -61,9 +67,11 @@ dependencies:
|
|
61
67
|
name: yard
|
62
68
|
prerelease: false
|
63
69
|
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
64
71
|
requirements:
|
65
72
|
- - ">="
|
66
73
|
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
67
75
|
segments:
|
68
76
|
- 0
|
69
77
|
version: "0"
|
@@ -80,7 +88,6 @@ extra_rdoc_files:
|
|
80
88
|
- README.rdoc
|
81
89
|
files:
|
82
90
|
- .document
|
83
|
-
- .gitignore
|
84
91
|
- LICENSE
|
85
92
|
- README.rdoc
|
86
93
|
- Rakefile
|
@@ -91,33 +98,36 @@ files:
|
|
91
98
|
- test/test_canable.rb
|
92
99
|
- test/test_cans.rb
|
93
100
|
- test/test_enforcers.rb
|
94
|
-
has_rdoc: true
|
95
101
|
homepage: http://github.com/jnunemaker/canable
|
96
102
|
licenses: []
|
97
103
|
|
98
104
|
post_install_message:
|
99
|
-
rdoc_options:
|
100
|
-
|
105
|
+
rdoc_options: []
|
106
|
+
|
101
107
|
require_paths:
|
102
108
|
- lib
|
103
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
104
111
|
requirements:
|
105
112
|
- - ">="
|
106
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
107
115
|
segments:
|
108
116
|
- 0
|
109
117
|
version: "0"
|
110
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
111
120
|
requirements:
|
112
121
|
- - ">="
|
113
122
|
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
114
124
|
segments:
|
115
125
|
- 0
|
116
126
|
version: "0"
|
117
127
|
requirements: []
|
118
128
|
|
119
129
|
rubyforge_project:
|
120
|
-
rubygems_version: 1.
|
130
|
+
rubygems_version: 1.7.2
|
121
131
|
signing_key:
|
122
132
|
specification_version: 3
|
123
133
|
summary: Simple permissions that I have used on my last several projects so I figured it was time to abstract and wrap up into something more easily reusable.
|