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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5a2c918a4ce721d081f323108d9f9830044fd87a
4
- data.tar.gz: 9fface794f302352233d3d5619be061aa3021f3e
2
+ SHA256:
3
+ metadata.gz: 7ec1a3ca2f6f4c400149f609889fadb35c99a6ad69381f4dc3a41290d5683008
4
+ data.tar.gz: 7c7029e01f9dc16d26b736824d4568001a0a76b6b6521e404caf38738797c0c4
5
5
  SHA512:
6
- metadata.gz: d50d8f6b6799208d26696852a5752e4f341ec6a1b50c425be39d25cc806ff049e49bc963d6da1f80a6f70ea829817ab2da9dffecb36385d307c9224e7c28c6a9
7
- data.tar.gz: 6207bc04306bb95083495a2fa3c2530505586e292a01a6a47f109413f28cd92606458d43611ebe109226db61559b53dbb2aef9fe631d7f448fc3c505ec0807e5
6
+ metadata.gz: b4315b8aaa24c7dc7978dc8865502e5bf4b492332464c1a5156111a74e43a7719c88e3f2b1ee255067517c192fca8a515a01a38df1687949706f239bd8d82122
7
+ data.tar.gz: fc5a915ca1fedebff489bcb3d521defd1b513de6232644adc3ce119c0019c41119b7ea32bc00e841ec2227edb2bba688121788f30d0d229b376d30f2d034d48f
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 1.1.0
4
+ - Loosens pundit version restriction so can be used with newer versions of pundit
5
+
1
6
  ## 1.0.0
2
7
 
3
8
  - Change `current_user` usage to `pundit_user`
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
@@ -1,3 +1,3 @@
1
1
  module PunditHelpers
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -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
@@ -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", "~> 0.2"
21
+ spec.add_dependency "pundit", ">= 0.2.2"
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.5"
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
@@ -21,46 +21,68 @@ class Harness
21
21
  include PunditHelpers
22
22
  end
23
23
 
24
- describe PunditHelpers, "#authorized?" do
25
- it "is true if #authorize returns true" do
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
- it "is false if #authorize raises Pundit::NotAuthorizedError" do
33
- harness = Harness.new
34
- record = double
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
- it "is installed as a helper_method on module inclusion" do
40
- expect(Harness.helper_methods).to include(:authorized?)
32
+ def show?
33
+ true
41
34
  end
42
35
  end
43
36
 
44
- describe PunditHelpers, "#can?" do
45
- it "is true if the located policy permits the action" do
46
- record = double
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
- expect(Pundit).to receive(:policy!).with(:spec_pundit_user, record).and_return(policy)
51
- expect(harness.can?(:edit, record)).to be_true
41
+ before do
42
+ allow(harness).to receive(:authorize).and_call_original
52
43
  end
53
44
 
54
- it "is false if the located policy denies the action" do
55
- record = double
56
- policy = double(:edit? => false)
57
- harness = Harness.new
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
- expect(Pundit).to receive(:policy!).with(:spec_pundit_user, record).and_return(policy)
60
- expect(harness.can?(:edit, record)).to be_false
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
- it "is installed as a helper_method on module inclusion" do
64
- expect(Harness.helper_methods).to include(:can?)
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.0.0
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: 2015-03-04 00:00:00.000000000 Z
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: '1.5'
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: '1.5'
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
- rubyforge_project:
112
- rubygems_version: 2.2.2
113
- signing_key:
106
+ rubygems_version: 3.3.11
107
+ signing_key:
114
108
  specification_version: 4
115
109
  summary: ''
116
110
  test_files: