restrict 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 40ecfe0fc4a56dfb106d72c936831d92ce4331d0082ead530c5eeaa47762dfcc
4
- data.tar.gz: 6ae9d487ae24a4c36fb7a8483e04acb1b0ec249cd5d86039638d4279e5d79dd3
3
+ metadata.gz: 64c201583341d1cfab486ba72a9a35562a2e453b15586f25a5403177e8e6af48
4
+ data.tar.gz: c73bcd768f66647315925df95a003e236fd31b1a22384a6670cb94ac5ab8cc96
5
5
  SHA512:
6
- metadata.gz: 5c7acadb64232f1b850265207d9288ab4c49bf7481cdf04a033dab7658983a8abfd463cb7c4a15a0d956b6d601dbf279930a0c137908431383d4c75c7a1f97ba
7
- data.tar.gz: 3e518e19c2fa5a9eaf3ba0239baa0288b6904cc6082077cba046e36b5953ee8631586e58cdbd33cd2779a40c45fbfc8ab9c9c91a60b7d08b98ee9eff2d507c25
6
+ metadata.gz: 7ff470658e364c155179b26ca04c6ba98c342ebc7c6a8bf3d1019f811c08c6ef9e726d06da5e8baa09f75dbbdba74c74553c4f664274f6db04741dbb7728a734
7
+ data.tar.gz: 66baa2c8609ba7cc6e2a47fc013e77db2dbb161c7329f6d0b41488d0ac718048ff8ba1a492b74a05363d26a371cf0feb28ffb700030e5356500d8e08b60e77f8
@@ -1,3 +1,6 @@
1
+ [0.1.1] - 2019-11-26
2
+ * Bug fix release to actually work in rails ¯\_(ツ)_/¯
3
+
1
4
  [0.1.0] - 2019-11-25
2
5
  * Support controller inheritance
3
6
 
@@ -3,16 +3,12 @@ module Restrict
3
3
  module Controller
4
4
  extend ActiveSupport::Concern
5
5
 
6
- def restrictions
7
- inherited_restrictions + self.class.__send__(:restrict_restrictions)
6
+ def inherited(subclass)
7
+ subclass.extend Restrict::Rails::Controller
8
8
  end
9
9
 
10
- def inherited_restrictions
11
- self.class.ancestors.map do |ancestor|
12
- if ancestor.instance_variable_get(:@restrict_gatekeeper_installed)
13
- ancestor.__send__(:restrict_restrictions)
14
- end
15
- end.compact.flatten
10
+ def restrictions
11
+ inherited_restrictions + self.class.__send__(:restrict_restrictions)
16
12
  end
17
13
 
18
14
  module ClassMethods
@@ -29,10 +25,6 @@ module Restrict
29
25
  @restrictions ||= []
30
26
  end
31
27
 
32
- def inherited(subclass)
33
- subclass.include Restrict::Rails::Controller
34
- end
35
-
36
28
  # This could happen in included block as well, but often you need
37
29
  # other before filters to happen before you actually check the
38
30
  # restrictions, so lets set it where it is used in the code as well.
@@ -45,6 +37,14 @@ module Restrict
45
37
 
46
38
  private
47
39
 
40
+ def inherited_restrictions
41
+ self.class.ancestors.map do |ancestor|
42
+ if ancestor.instance_variable_get(:@restrict_gatekeeper_installed)
43
+ ancestor.__send__(:restrict_restrictions)
44
+ end
45
+ end.compact.flatten
46
+ end
47
+
48
48
  def invoke_gatekeeper
49
49
  Restrict::Gatekeeper.new.eye(self)
50
50
  end
@@ -1,3 +1,3 @@
1
1
  module Restrict
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -58,4 +58,22 @@ describe Restrict::Rails::Controller do
58
58
  expect(child).to have_restriction_on(:show).unless(:level3?)
59
59
  end
60
60
  end
61
+
62
+ describe 'applies inherited general restrictions additionally to explizit restrictions' do
63
+ let(:base) { ExampleController.new }
64
+ let(:controller) { InheritingController.new }
65
+
66
+ before do
67
+ base.class.restrict unless: :level1?
68
+ controller.class.restrict :show, unless: :level2?
69
+ end
70
+
71
+ it 'does not leak restrictions into superclass' do
72
+ expect(base).to have_restriction_on(:show).unless(:level1?)
73
+ expect(base).not_to have_restriction_on(:show).unless(:level2?)
74
+
75
+ expect(controller).to have_restriction_on(:show).unless(:level1?)
76
+ expect(controller).to have_restriction_on(:show).unless(:level2?)
77
+ end
78
+ end
61
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restrict
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Opper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-27 00:00:00.000000000 Z
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails