indulgence 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.rdoc +7 -0
- data/lib/indulgence/permission.rb +6 -1
- data/lib/indulgence/version.rb +5 -1
- data/test/db/test.sqlite3.db +0 -0
- data/test/units/indulgence/permission_test.rb +5 -0
- data/test/units/role_permission_test.rb +11 -0
- data/test/units/thing_permission_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTA1YTM4YmFhMGUzMTIxNzYwOWQ4YzYzZTM3NmRhNjc2YjY3NzdiZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGNkZDE1ZDk0ZGE4ZjcyZTQzYjlhZGQxNTczOTVhMjY2ZTRlZTYyNg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjNmNGMyZWEyNWIyNmRlYTJjMTcxODVkMGQ2ZWM0ODVmZGJhZTcyZWZmYzNi
|
10
|
+
ZTFlMTg2ODVmNzY4NDgzMzM1Y2NmN2Q0Mzc3NzM0NDBmMDEzNDYwZTc0ZGVk
|
11
|
+
YzY2ZWI2NzQ5ZDk3MjM3OWViNjNiYmQ0ZGNiNGM5NDA2OWNjMWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTg5ODNkMmJiYTllM2M5NjU5ODg3ODcxYzdmY2M1NTc2NTBiZGQ4YmI2NjY3
|
14
|
+
ZjM1YWY1OWZlMDY5NTdiMjE1NjBiMGFiYzcwYjA1MDBhNjZjNTI2MzMwYzdi
|
15
|
+
NGFiYzhkMWRiZDE0ZTYwMjZiMjhlYjE5ZWU0YWFlNDRmMGQ5NDA=
|
data/README.rdoc
CHANGED
@@ -373,6 +373,13 @@ With this used to define indulgence in Thing, we can do this:
|
|
373
373
|
Thing.permitted(cicero, :create) == [thing]
|
374
374
|
Thing.permitted(cicero, :read) == Thing.all
|
375
375
|
|
376
|
+
== Null entities
|
377
|
+
|
378
|
+
Indulgence falls back to the *none* ability if _nil_ is passed as the entity.
|
379
|
+
|
380
|
+
thing.indule?(nil, :read) == false
|
381
|
+
Thing.indulgence(nil, :read) --> raises ActiveRecord::RecordNotFound
|
382
|
+
|
376
383
|
== Examples
|
377
384
|
|
378
385
|
For some examples, have a look at the tests. In particular, look at the object
|
@@ -13,7 +13,7 @@ module Indulgence
|
|
13
13
|
{}
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
16
|
+
def null_entity
|
17
17
|
{
|
18
18
|
create: none,
|
19
19
|
read: none,
|
@@ -21,6 +21,10 @@ module Indulgence
|
|
21
21
|
delete: none
|
22
22
|
}
|
23
23
|
end
|
24
|
+
|
25
|
+
def default
|
26
|
+
null_entity
|
27
|
+
end
|
24
28
|
|
25
29
|
def filter_many(things)
|
26
30
|
ability.filter_many things, entity
|
@@ -80,6 +84,7 @@ module Indulgence
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def abilities_for_role
|
87
|
+
return null_entity unless entity
|
83
88
|
abilities[role_name] || default
|
84
89
|
end
|
85
90
|
|
data/lib/indulgence/version.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
module Indulgence
|
2
|
-
VERSION = "0.0
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
4
4
|
|
5
5
|
# History
|
6
6
|
# =======
|
7
7
|
#
|
8
|
+
# 0.1.0 Handles a nil entity being passed to either indulge? or indulgence.
|
9
|
+
# Code now tried and tested in a number of applications, so
|
10
|
+
# bumping up to 0.1.
|
11
|
+
#
|
8
12
|
# 0.0.7 Adds Thing.indulge? class method.
|
9
13
|
#
|
10
14
|
# 0.0.6 Specifies the default behaviour as assigning the none ability to
|
data/test/db/test.sqlite3.db
CHANGED
Binary file
|
@@ -25,5 +25,10 @@ module Indulgence
|
|
25
25
|
assert_equal Ability, Permission.send(:ability_cache)[:test_ability].class
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_creation_with_null_entity
|
29
|
+
permission = Permission.new(nil, :read)
|
30
|
+
assert_equal Permission.none, permission.ability
|
31
|
+
end
|
32
|
+
|
28
33
|
end
|
29
34
|
end
|
@@ -20,6 +20,17 @@ class RolePermissionTest < Test::Unit::TestCase
|
|
20
20
|
Role.indulgence(@user, :delete)
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def test_null_entity_indulge
|
25
|
+
assert_equal(false, @role.indulge?(nil, :update))
|
26
|
+
assert_not_equal(@role.indulge?(@user, :update), @role.indulge?(nil, :update))
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_null_entity_indulgence
|
30
|
+
assert_raise ActiveRecord::RecordNotFound do
|
31
|
+
assert_equal(0, Role.indulgence(nil, :update).count)
|
32
|
+
end
|
33
|
+
end
|
23
34
|
|
24
35
|
def teardown
|
25
36
|
User.delete_all
|
@@ -29,6 +29,13 @@ class ThingPermissionTest < Test::Unit::TestCase
|
|
29
29
|
assert_equal Permission.none, ThingPermission.new(@user, :update).ability
|
30
30
|
assert_equal Permission.none, ThingPermission.new(@user, :delete).ability
|
31
31
|
end
|
32
|
+
|
33
|
+
def test_null_entity
|
34
|
+
assert_equal Permission.none, ThingPermission.new(nil, :create).ability
|
35
|
+
assert_equal Permission.none, ThingPermission.new(nil, :read).ability
|
36
|
+
assert_equal Permission.none, ThingPermission.new(nil, :update).ability
|
37
|
+
assert_equal Permission.none, ThingPermission.new(nil, :delete).ability
|
38
|
+
end
|
32
39
|
|
33
40
|
def test_role_name
|
34
41
|
assert_equal @super_user.role.name.to_sym, ThingPermission.new(@super_user, :read).role_name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: indulgence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Nichols
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|