cancannible 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Rakefile +2 -2
- data/lib/cancannible/grantee.rb +3 -6
- data/lib/cancannible/version.rb +1 -1
- data/lib/cancannible.rb +1 -1
- data/spec/unit/cached_abilities_spec.rb +4 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb16c35b4fdf331771322c61a13d78d34e6e75eb97b26b06e8745ec0bf86ff4
|
4
|
+
data.tar.gz: 88d347b2f3dccf1e8fa6c38413676d38d89e7ad654ef425e70da5de5dce79592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e418c7689141e1967e44d011da10579dd6d1439bab2043ec5d71088a7f7f916be8496aa8dcf04c9c65bc70367980e32206e8c7029da2ccfb3fc52d7bc338b20
|
7
|
+
data.tar.gz: 481bdcff9e0e8501070e4c0ca1e0d4400e65708608bdcfaa6a7fd551d5783849eba6808bda6fe3e97c3df18c12b6c04764363bc1cb25e623e06803b67aeb0301
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/lib/cancannible/grantee.rb
CHANGED
@@ -51,12 +51,9 @@ module Cancannible::Grantee
|
|
51
51
|
nil
|
52
52
|
elsif Cancannible.get_cached_abilities.respond_to?(:call)
|
53
53
|
result = Cancannible.get_cached_abilities.call(self)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
rules_index_size = (result.instance_variable_get(:@rules_index) || []).size
|
58
|
-
result if !rules_size.nil? && rules_index_size == rules_size
|
59
|
-
end
|
54
|
+
# performs a crude compatibility check: cancan rules won't have a @rules_index
|
55
|
+
# (neither will an empty ability object, but we ignore this case)
|
56
|
+
result unless result && !result.instance_variable_defined?(:@rules_index)
|
60
57
|
end
|
61
58
|
return @abilities if @abilities
|
62
59
|
|
data/lib/cancannible/version.rb
CHANGED
data/lib/cancannible.rb
CHANGED
@@ -40,7 +40,7 @@ describe Cancannible do
|
|
40
40
|
context "when store_cached_abilities provided" do
|
41
41
|
before do
|
42
42
|
@stored = nil
|
43
|
-
Cancannible.store_cached_abilities = proc { |grantee, ability| @stored = { grantee_id: grantee.id, ability:
|
43
|
+
Cancannible.store_cached_abilities = proc { |grantee, ability| @stored = { grantee_id: grantee.id, ability: cached_object } }
|
44
44
|
end
|
45
45
|
it "stores the cached object" do
|
46
46
|
expect { subject }.to change { @stored }.from(nil)
|
@@ -53,28 +53,26 @@ describe Cancannible do
|
|
53
53
|
before do
|
54
54
|
@stored = nil
|
55
55
|
@store = 0
|
56
|
-
Cancannible.get_cached_abilities = proc { |grantee| @stored
|
56
|
+
Cancannible.get_cached_abilities = proc { |grantee| @stored && cached_object }
|
57
57
|
Cancannible.store_cached_abilities = proc { |grantee, ability| @store += 1 ; @stored = { grantee_id: grantee.id, ability: ability } }
|
58
58
|
end
|
59
59
|
it "stores the cached object on the first call" do
|
60
60
|
expect { subject }.to change { @stored }.from(nil)
|
61
61
|
expect(@store).to eql(1)
|
62
|
-
expect(
|
63
|
-
expect(
|
62
|
+
expect(grantee.abilities.instance_variable_get(:@rules).size).to eql(1)
|
63
|
+
expect(grantee.abilities.instance_variable_get(:@rules_index).size).to eql(1)
|
64
64
|
end
|
65
65
|
it "returns the cached object on the second call" do
|
66
66
|
expect { subject }.to change { @stored }.from(nil)
|
67
67
|
expect(@store).to eql(1)
|
68
68
|
expect { grantee.abilities }.to_not change { @store }
|
69
69
|
expect(grantee.abilities).to be_an(Ability)
|
70
|
-
expect(@stored[:grantee_id]).to eql(grantee.id)
|
71
70
|
end
|
72
71
|
it "should re-cache object on the second call if refresh requested" do
|
73
72
|
expect { subject }.to change { @stored }.from(nil)
|
74
73
|
expect(@store).to eql(1)
|
75
74
|
expect { grantee.abilities(true) }.to change { @store }.from(1).to(2)
|
76
75
|
expect(grantee.abilities).to be_an(Ability)
|
77
|
-
expect(@stored[:grantee_id]).to eql(grantee.id)
|
78
76
|
end
|
79
77
|
end
|
80
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancannible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Gallagher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|