pundit_helpers 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: eabe76151f5ab089cd71e22a1eaf07f5ac46e405
4
- data.tar.gz: 65e3da497c6d5000e8b6e93153227b085519b0b7
3
+ metadata.gz: b8c455b30750a6b3dc536ecacf295af59bafd288
4
+ data.tar.gz: c335ff2a0838b73bd76e3a4c7a1ea8f673d51f35
5
5
  SHA512:
6
- metadata.gz: 0f48e47729f0b5464cb4167077e20a686b0cb63cd50bb278b4a070085a743dda9f861b89e0ef5d95758fa29dbcf7cf4eb302f82d786b1b77bdd2e1eb47602625
7
- data.tar.gz: a9934477a2f25f26ac1c186208de1238b91f4f01c77b267d2644632f2e7516aa7360af56897f095d72a0162bcb1b435edfeae08f8c37f93b875d4303d09b5d9c
6
+ metadata.gz: fc416de6a4a76cca6546f4e0607ea0fc341e2d675adb3a0cf5d762fa117abb5fab1243e302e54f3347f10ea890dea69c34e038eea86812ab74a0ea5765727dc1
7
+ data.tar.gz: eaa6916e9b7bef6ea327fa47edb8104f7935d77a15a17b20f407ebf41cf04341427c7f4320304a8c93e7192ed297661cc1a113e25de00bef7a4a74c059eba9cf
@@ -1,3 +1,3 @@
1
1
  module PunditHelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,6 +1,17 @@
1
1
  require "pundit_helpers/version"
2
2
 
3
3
  module PunditHelpers
4
+ def self.included(base)
5
+ methods = [:authorized?, :can?]
6
+
7
+ if base.respond_to?(:helper_method)
8
+ methods.each { |m| base.helper_method(m) }
9
+ end
10
+
11
+ if respond_to?(:hide_action)
12
+ methods.each { |m| base.hide_action(m) }
13
+ end
14
+ end
4
15
  # Pundit's core `#authorize` helper always raises
5
16
  # an error, but also lets the controller know an authorization
6
17
  # has been performed. Sometimes it is preferrable to flag that an
@@ -2,11 +2,23 @@ require "pundit"
2
2
  require "pundit_helpers"
3
3
 
4
4
  class Harness
5
- include PunditHelpers
5
+ def initialize
6
+ @helper_methods = []
7
+ end
6
8
 
7
9
  def current_user
8
10
  :spec_current_user
9
11
  end
12
+
13
+ def self.helper_methods
14
+ @helper_methods ||= []
15
+ end
16
+
17
+ def self.helper_method(name)
18
+ self.helper_methods << name
19
+ end
20
+
21
+ include PunditHelpers
10
22
  end
11
23
 
12
24
  describe PunditHelpers, "#authorized?" do
@@ -23,6 +35,10 @@ describe PunditHelpers, "#authorized?" do
23
35
  expect(harness).to receive(:authorize).with(record, :show?).and_raise(Pundit::NotAuthorizedError)
24
36
  expect(harness.authorized?(record, :show?)).to be_false
25
37
  end
38
+
39
+ it "is installed as a helper_method on module inclusion" do
40
+ expect(Harness.helper_methods).to include(:authorized?)
41
+ end
26
42
  end
27
43
 
28
44
  describe PunditHelpers, "#can?" do
@@ -43,4 +59,8 @@ describe PunditHelpers, "#can?" do
43
59
  expect(Pundit).to receive(:policy!).with(:spec_current_user, record).and_return(policy)
44
60
  expect(harness.can?(:edit, record)).to be_false
45
61
  end
62
+
63
+ it "is installed as a helper_method on module inclusion" do
64
+ expect(Harness.helper_methods).to include(:can?)
65
+ end
46
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pundit_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brendon Murphy