cancannible 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ba63fd7b6b80a32a3bc93fbbe43845439c1eaffa9661e35510dbeff487af673
4
- data.tar.gz: fdf8f225705b0e0fa9ea469674d62ce22b5340f48cb23fb94a2b8501112417cf
3
+ metadata.gz: ecb16c35b4fdf331771322c61a13d78d34e6e75eb97b26b06e8745ec0bf86ff4
4
+ data.tar.gz: 88d347b2f3dccf1e8fa6c38413676d38d89e7ad654ef425e70da5de5dce79592
5
5
  SHA512:
6
- metadata.gz: f9068c6dce19852c747512ddafa0a29461586128d67408bc5c53f07e029e8273d0cb343acb4400dcfd180afd6596202837fac699838f62d6e252a56dd35f99df
7
- data.tar.gz: e5ec5d5accb0e40139dbeee9b6bc211d3652688c7ffb17c1788c86cea455c626914b233d4eb52de2786993989df8018d38ddfb07bef5bedb2f04484d43f62054
6
+ metadata.gz: 5e418c7689141e1967e44d011da10579dd6d1439bab2043ec5d71088a7f7f916be8496aa8dcf04c9c65bc70367980e32206e8c7029da2ccfb3fc52d7bc338b20
7
+ data.tar.gz: 481bdcff9e0e8501070e4c0ca1e0d4400e65708608bdcfaa6a7fd551d5783849eba6808bda6fe3e97c3df18c12b6c04764363bc1cb25e623e06803b67aeb0301
data/.gitignore CHANGED
@@ -22,3 +22,4 @@ tmp
22
22
  mkmf.log
23
23
  .rvm*
24
24
  .ruby*
25
+ .byebug_history
data/Rakefile CHANGED
@@ -7,5 +7,5 @@ task :default => :spec
7
7
 
8
8
  desc "Open an irb session preloaded with this library"
9
9
  task :console do
10
- sh "irb -rubygems -I lib -r cancannible.rb"
11
- end
10
+ sh "irb -I lib -r cancannible.rb"
11
+ end
@@ -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
- if result
55
- # performs a crude compatibility check
56
- rules_size = result.send(:rules).size rescue nil
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
 
@@ -1,3 +1,3 @@
1
1
  module Cancannible
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
data/lib/cancannible.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
- require 'cancan'
3
+ require 'cancancan'
4
4
 
5
5
  require 'cancannible/version'
6
6
  require 'cancannible/config'
@@ -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: 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[:ability] if @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(@stored[:grantee_id]).to eql(grantee.id)
63
- expect(@stored[:ability]).to be_an(Ability)
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.0.0
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-03-01 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport