pundit_helpers 1.0.0 → 1.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 +5 -5
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +61 -0
- data/lib/pundit_helpers/version.rb +1 -1
- data/lib/pundit_helpers.rb +5 -1
- data/pundit_helpers.gemspec +2 -2
- data/spec/pundit_helpers_spec.rb +52 -30
- metadata +12 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7ec1a3ca2f6f4c400149f609889fadb35c99a6ad69381f4dc3a41290d5683008
|
4
|
+
data.tar.gz: 7c7029e01f9dc16d26b736824d4568001a0a76b6b6521e404caf38738797c0c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4315b8aaa24c7dc7978dc8865502e5bf4b492332464c1a5156111a74e43a7719c88e3f2b1ee255067517c192fca8a515a01a38df1687949706f239bd8d82122
|
7
|
+
data.tar.gz: fc5a915ca1fedebff489bcb3d521defd1b513de6232644adc3ce119c0019c41119b7ea32bc00e841ec2227edb2bba688121788f30d0d229b376d30f2d034d48f
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pundit_helpers (1.1.0)
|
5
|
+
pundit (>= 0.2.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.1.5.1)
|
11
|
+
base64
|
12
|
+
benchmark (>= 0.3)
|
13
|
+
bigdecimal
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
17
|
+
i18n (>= 1.6, < 2)
|
18
|
+
logger (>= 1.4.2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
mutex_m
|
21
|
+
securerandom (>= 0.3)
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
base64 (0.2.0)
|
24
|
+
benchmark (0.4.0)
|
25
|
+
bigdecimal (3.1.9)
|
26
|
+
concurrent-ruby (1.3.4)
|
27
|
+
connection_pool (2.5.0)
|
28
|
+
diff-lcs (1.5.1)
|
29
|
+
drb (2.2.1)
|
30
|
+
i18n (1.14.6)
|
31
|
+
concurrent-ruby (~> 1.0)
|
32
|
+
logger (1.6.4)
|
33
|
+
minitest (5.25.4)
|
34
|
+
mutex_m (0.3.0)
|
35
|
+
pundit (2.4.0)
|
36
|
+
activesupport (>= 3.0.0)
|
37
|
+
rake (13.2.1)
|
38
|
+
rspec (2.14.1)
|
39
|
+
rspec-core (~> 2.14.0)
|
40
|
+
rspec-expectations (~> 2.14.0)
|
41
|
+
rspec-mocks (~> 2.14.0)
|
42
|
+
rspec-core (2.14.8)
|
43
|
+
rspec-expectations (2.14.5)
|
44
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
45
|
+
rspec-mocks (2.14.6)
|
46
|
+
securerandom (0.3.2)
|
47
|
+
tzinfo (2.0.6)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
arm64-darwin-23
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
bundler
|
56
|
+
pundit_helpers!
|
57
|
+
rake
|
58
|
+
rspec (~> 2.14.1)
|
59
|
+
|
60
|
+
BUNDLED WITH
|
61
|
+
2.5.17
|
data/lib/pundit_helpers.rb
CHANGED
@@ -2,6 +2,10 @@ require "pundit_helpers/version"
|
|
2
2
|
|
3
3
|
module PunditHelpers
|
4
4
|
def self.included(base)
|
5
|
+
unless ancestors.include?(Pundit)
|
6
|
+
include Pundit::Authorization
|
7
|
+
end
|
8
|
+
|
5
9
|
methods = [:authorized?, :can?]
|
6
10
|
|
7
11
|
if base.respond_to?(:helper_method)
|
@@ -27,7 +31,7 @@ module PunditHelpers
|
|
27
31
|
# @return [Boolean]
|
28
32
|
def authorized?(record, query=nil)
|
29
33
|
begin
|
30
|
-
authorize(record, query)
|
34
|
+
!!authorize(record, query)
|
31
35
|
rescue Pundit::NotAuthorizedError
|
32
36
|
false
|
33
37
|
end
|
data/pundit_helpers.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "pundit", ">= 0.2.2"
|
21
|
+
spec.add_dependency "pundit", ">= 0.2.2"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec", "~> 2.14.1"
|
26
26
|
end
|
data/spec/pundit_helpers_spec.rb
CHANGED
@@ -21,46 +21,68 @@ class Harness
|
|
21
21
|
include PunditHelpers
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
harness = Harness.new
|
27
|
-
record = double
|
28
|
-
expect(harness).to receive(:authorize).with(record, :show?).and_return(true)
|
29
|
-
expect(harness.authorized?(record, :show?)).to be_true
|
30
|
-
end
|
24
|
+
class Post
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
expect(harness).to receive(:authorize).with(record, :show?).and_raise(Pundit::NotAuthorizedError)
|
36
|
-
expect(harness.authorized?(record, :show?)).to be_false
|
27
|
+
class PostPolicy < Struct.new(:user, :post)
|
28
|
+
def edit?
|
29
|
+
user == :mr_joe
|
37
30
|
end
|
38
31
|
|
39
|
-
|
40
|
-
|
32
|
+
def show?
|
33
|
+
true
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
44
|
-
describe PunditHelpers
|
45
|
-
|
46
|
-
|
47
|
-
policy = double(:edit? => true)
|
48
|
-
harness = Harness.new
|
37
|
+
describe PunditHelpers do
|
38
|
+
let(:harness) { Harness.new }
|
39
|
+
let(:record) { Post.new }
|
49
40
|
|
50
|
-
|
51
|
-
|
41
|
+
before do
|
42
|
+
allow(harness).to receive(:authorize).and_call_original
|
52
43
|
end
|
53
44
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
45
|
+
describe "#authorized?" do
|
46
|
+
context "when authorization succeeds" do
|
47
|
+
it "is true if #authorize returns true" do
|
48
|
+
expect(harness.authorized?(record, :show?)).to eq true
|
49
|
+
expect(harness).to have_received(:authorize).with(record, :show?)
|
50
|
+
end
|
51
|
+
end
|
58
52
|
|
59
|
-
|
60
|
-
|
53
|
+
context "when authorization fails" do
|
54
|
+
it "is false if #authorize raises Pundit::NotAuthorizedError" do
|
55
|
+
expect(harness.authorized?(record, :edit?)).to be false
|
56
|
+
expect(harness).to have_received(:authorize).with(record, :edit?)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "is installed as a helper_method on module inclusion" do
|
61
|
+
expect(Harness.helper_methods).to include(:authorized?)
|
62
|
+
end
|
61
63
|
end
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
+
describe "#can?" do
|
66
|
+
let(:policy) { PostPolicy.new(:spec_pundit_user, record) }
|
67
|
+
|
68
|
+
before do
|
69
|
+
allow(Pundit).to receive(:policy!)
|
70
|
+
.with(:spec_pundit_user, record)
|
71
|
+
.and_return(policy)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "is true if the located policy permits the action" do
|
75
|
+
expect(harness.can?(:show, record)).to be true
|
76
|
+
expect(Pundit).to have_received(:policy!).with(:spec_pundit_user, record)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "is false if the located policy denies the action" do
|
80
|
+
expect(harness.can?(:edit, record)).to be false
|
81
|
+
expect(Pundit).to have_received(:policy!).with(:spec_pundit_user, record)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "is installed as a helper_method on module inclusion" do
|
85
|
+
expect(Harness.helper_methods).to include(:can?)
|
86
|
+
end
|
65
87
|
end
|
66
|
-
end
|
88
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brendon Murphy
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pundit
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.2.2
|
20
|
-
- - "~>"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '0.2'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,23 +24,20 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.2.2
|
30
|
-
- - "~>"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '0.2'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: bundler
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "
|
31
|
+
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
33
|
+
version: '0'
|
40
34
|
type: :development
|
41
35
|
prerelease: false
|
42
36
|
version_requirements: !ruby/object:Gem::Requirement
|
43
37
|
requirements:
|
44
|
-
- - "
|
38
|
+
- - ">="
|
45
39
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
40
|
+
version: '0'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rake
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,7 +66,7 @@ dependencies:
|
|
72
66
|
- - "~>"
|
73
67
|
- !ruby/object:Gem::Version
|
74
68
|
version: 2.14.1
|
75
|
-
description:
|
69
|
+
description:
|
76
70
|
email:
|
77
71
|
- xternal1+github@gmail.com
|
78
72
|
executables: []
|
@@ -82,6 +76,7 @@ files:
|
|
82
76
|
- ".gitignore"
|
83
77
|
- CHANGELOG.md
|
84
78
|
- Gemfile
|
79
|
+
- Gemfile.lock
|
85
80
|
- LICENSE.txt
|
86
81
|
- README.md
|
87
82
|
- Rakefile
|
@@ -93,7 +88,7 @@ homepage: ''
|
|
93
88
|
licenses:
|
94
89
|
- MIT
|
95
90
|
metadata: {}
|
96
|
-
post_install_message:
|
91
|
+
post_install_message:
|
97
92
|
rdoc_options: []
|
98
93
|
require_paths:
|
99
94
|
- lib
|
@@ -108,9 +103,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
103
|
- !ruby/object:Gem::Version
|
109
104
|
version: '0'
|
110
105
|
requirements: []
|
111
|
-
|
112
|
-
|
113
|
-
signing_key:
|
106
|
+
rubygems_version: 3.3.11
|
107
|
+
signing_key:
|
114
108
|
specification_version: 4
|
115
109
|
summary: ''
|
116
110
|
test_files:
|