pundit_helpers 0.0.1 → 0.0.2
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 +4 -4
- data/lib/pundit_helpers/version.rb +1 -1
- data/lib/pundit_helpers.rb +11 -0
- data/spec/pundit_helpers_spec.rb +21 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8c455b30750a6b3dc536ecacf295af59bafd288
|
4
|
+
data.tar.gz: c335ff2a0838b73bd76e3a4c7a1ea8f673d51f35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc416de6a4a76cca6546f4e0607ea0fc341e2d675adb3a0cf5d762fa117abb5fab1243e302e54f3347f10ea890dea69c34e038eea86812ab74a0ea5765727dc1
|
7
|
+
data.tar.gz: eaa6916e9b7bef6ea327fa47edb8104f7935d77a15a17b20f407ebf41cf04341427c7f4320304a8c93e7192ed297661cc1a113e25de00bef7a4a74c059eba9cf
|
data/lib/pundit_helpers.rb
CHANGED
@@ -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
|
data/spec/pundit_helpers_spec.rb
CHANGED
@@ -2,11 +2,23 @@ require "pundit"
|
|
2
2
|
require "pundit_helpers"
|
3
3
|
|
4
4
|
class Harness
|
5
|
-
|
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
|