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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2e10a94ed9f8cbd38d1c51f38344eedd7d680d8
4
- data.tar.gz: 89b88467b3f85513d764ff7f2357f98dfa078b5c
3
+ metadata.gz: e2a27c306e9cc67fc0ecabc8c910f7e4a5b0706a
4
+ data.tar.gz: e94f7b364462ea0cf5b4c30d48620f523d89ff4a
5
5
  SHA512:
6
- metadata.gz: 78331e942eabf7eb0b0990e0760481498cd056f10f3b11ecc7f9fb9718ae6532a1bd64a3682d012d8245ab019cf39f2e8671dff82e55dee1bf4e76afcf62dd05
7
- data.tar.gz: c95f7e2fb27998009aeb6948464ce550938fc59a21d9169d0def6df7b3e467140f2d00fa198b97adce8cb08d232bd42d95cda46ab84813e08f305cc2277aee40
6
+ metadata.gz: d754a6ba6a9b2c00eff1100c320cba4ab34dbca2877e966d477febec75aa79348b978397f53a7961f771f694ac377fb0b87a4af8e79be75e840d15ff0cf53189
7
+ data.tar.gz: ce78572422e59c3cd811b9062cc033aabfe69713a7e7ee364a0fe12c505f4399ebbd645683d0935b1f045af8903835e9a97d31e47edcf2928c4fd90f89cbe87d
@@ -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.
@@ -14,11 +14,15 @@ module Pundit
14
14
  attr_reader :query, :record, :policy
15
15
 
16
16
  def initialize(options = {})
17
- @query = options[:query]
18
- @record = options[:record]
19
- @policy = options[:policy]
20
-
21
- message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
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
@@ -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.classify
50
+ object.to_s.camelize
51
51
  elsif object.is_a?(Array)
52
- object.join('/').to_s.classify
52
+ object.join('/').camelize
53
53
  else
54
54
  object.class
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module Pundit
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -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, :dashboard)
142
- expect(policy.class).to eq DashboardPolicy
141
+ policy = Pundit.policy(user, :criteria)
142
+ expect(policy.class).to eq CriteriaPolicy
143
143
  expect(policy.user).to eq user
144
- expect(policy.dashboard).to eq :dashboard
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, :dashboard])
149
- expect(policy.class).to eq Project::DashboardPolicy
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.dashboard).to eq [:project, :dashboard]
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, :dashboard)
183
- expect(policy.class).to eq DashboardPolicy
182
+ policy = Pundit.policy!(user, :criteria)
183
+ expect(policy.class).to eq CriteriaPolicy
184
184
  expect(policy.user).to eq user
185
- expect(policy.dashboard).to eq :dashboard
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, :dashboard])
190
- expect(policy.class).to eq Project::DashboardPolicy
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.dashboard).to eq [:project, :dashboard]
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
@@ -93,10 +93,10 @@ class ArticleTag
93
93
  end
94
94
  end
95
95
 
96
- class DashboardPolicy < Struct.new(:user, :dashboard); end
96
+ class CriteriaPolicy < Struct.new(:user, :criteria); end
97
97
 
98
98
  module Project
99
- class DashboardPolicy < Struct.new(:user, :dashboard); end
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.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-04-19 00:00:00.000000000 Z
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.5
181
+ rubygems_version: 2.4.6
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: OO authorization for Rails