pundit 1.0.0 → 1.0.1
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/CHANGELOG.md +5 -0
- data/lib/pundit.rb +9 -5
- data/lib/pundit/policy_finder.rb +2 -2
- data/lib/pundit/version.rb +1 -1
- data/spec/pundit_spec.rb +19 -12
- data/spec/spec_helper.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2a27c306e9cc67fc0ecabc8c910f7e4a5b0706a
|
4
|
+
data.tar.gz: e94f7b364462ea0cf5b4c30d48620f523d89ff4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d754a6ba6a9b2c00eff1100c320cba4ab34dbca2877e966d477febec75aa79348b978397f53a7961f771f694ac377fb0b87a4af8e79be75e840d15ff0cf53189
|
7
|
+
data.tar.gz: ce78572422e59c3cd811b9062cc033aabfe69713a7e7ee364a0fe12c505f4399ebbd645683d0935b1f045af8903835e9a97d31e47edcf2928c4fd90f89cbe87d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Pundit
|
2
2
|
|
3
|
+
## 1.0.1 (2015-05-27)
|
4
|
+
|
5
|
+
- Fixed a regression where NotAuthorizedError could not be ininitialized with a string.
|
6
|
+
- Use `camelize` instead of `classify` for symbol policies to prevent weird pluralizations.
|
7
|
+
|
3
8
|
## 1.0.0 (2015-04-19)
|
4
9
|
|
5
10
|
- Caches policy scopes and policies.
|
data/lib/pundit.rb
CHANGED
@@ -14,11 +14,15 @@ module Pundit
|
|
14
14
|
attr_reader :query, :record, :policy
|
15
15
|
|
16
16
|
def initialize(options = {})
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
if options.is_a? String
|
18
|
+
message = options
|
19
|
+
else
|
20
|
+
@query = options[:query]
|
21
|
+
@record = options[:record]
|
22
|
+
@policy = options[:policy]
|
23
|
+
|
24
|
+
message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
|
25
|
+
end
|
22
26
|
|
23
27
|
super(message)
|
24
28
|
end
|
data/lib/pundit/policy_finder.rb
CHANGED
@@ -47,9 +47,9 @@ module Pundit
|
|
47
47
|
elsif object.is_a?(Class)
|
48
48
|
object
|
49
49
|
elsif object.is_a?(Symbol)
|
50
|
-
object.to_s.
|
50
|
+
object.to_s.camelize
|
51
51
|
elsif object.is_a?(Array)
|
52
|
-
object.join('/').
|
52
|
+
object.join('/').camelize
|
53
53
|
else
|
54
54
|
object.class
|
55
55
|
end
|
data/lib/pundit/version.rb
CHANGED
data/spec/pundit_spec.rb
CHANGED
@@ -138,17 +138,17 @@ describe Pundit do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it "returns an instantiated policy given a symbol" do
|
141
|
-
policy = Pundit.policy(user, :
|
142
|
-
expect(policy.class).to eq
|
141
|
+
policy = Pundit.policy(user, :criteria)
|
142
|
+
expect(policy.class).to eq CriteriaPolicy
|
143
143
|
expect(policy.user).to eq user
|
144
|
-
expect(policy.
|
144
|
+
expect(policy.criteria).to eq :criteria
|
145
145
|
end
|
146
146
|
|
147
147
|
it "returns an instantiated policy given an array" do
|
148
|
-
policy = Pundit.policy(user, [:project, :
|
149
|
-
expect(policy.class).to eq Project::
|
148
|
+
policy = Pundit.policy(user, [:project, :criteria])
|
149
|
+
expect(policy.class).to eq Project::CriteriaPolicy
|
150
150
|
expect(policy.user).to eq user
|
151
|
-
expect(policy.
|
151
|
+
expect(policy.criteria).to eq [:project, :criteria]
|
152
152
|
end
|
153
153
|
end
|
154
154
|
end
|
@@ -179,17 +179,17 @@ describe Pundit do
|
|
179
179
|
end
|
180
180
|
|
181
181
|
it "returns an instantiated policy given a symbol" do
|
182
|
-
policy = Pundit.policy!(user, :
|
183
|
-
expect(policy.class).to eq
|
182
|
+
policy = Pundit.policy!(user, :criteria)
|
183
|
+
expect(policy.class).to eq CriteriaPolicy
|
184
184
|
expect(policy.user).to eq user
|
185
|
-
expect(policy.
|
185
|
+
expect(policy.criteria).to eq :criteria
|
186
186
|
end
|
187
187
|
|
188
188
|
it "returns an instantiated policy given an array" do
|
189
|
-
policy = Pundit.policy!(user, [:project, :
|
190
|
-
expect(policy.class).to eq Project::
|
189
|
+
policy = Pundit.policy!(user, [:project, :criteria])
|
190
|
+
expect(policy.class).to eq Project::CriteriaPolicy
|
191
191
|
expect(policy.user).to eq user
|
192
|
-
expect(policy.
|
192
|
+
expect(policy.criteria).to eq [:project, :criteria]
|
193
193
|
end
|
194
194
|
|
195
195
|
it "throws an exception if the given policy can't be found" do
|
@@ -344,4 +344,11 @@ describe Pundit do
|
|
344
344
|
expect(Controller.new(double, params).permitted_attributes(post)).to eq({ 'votes' => 5 })
|
345
345
|
end
|
346
346
|
end
|
347
|
+
|
348
|
+
describe "Pundit::NotAuthorizedError" do
|
349
|
+
it "can be initialized with a string as message" do
|
350
|
+
error = Pundit::NotAuthorizedError.new("must be logged in")
|
351
|
+
expect(error.message).to eq "must be logged in"
|
352
|
+
end
|
353
|
+
end
|
347
354
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -93,10 +93,10 @@ class ArticleTag
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
class
|
96
|
+
class CriteriaPolicy < Struct.new(:user, :criteria); end
|
97
97
|
|
98
98
|
module Project
|
99
|
-
class
|
99
|
+
class CriteriaPolicy < Struct.new(:user, :criteria); end
|
100
100
|
end
|
101
101
|
|
102
102
|
class DenierPolicy < Struct.new(:user, :record)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.4.
|
181
|
+
rubygems_version: 2.4.6
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: OO authorization for Rails
|