pundit-matchers 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pundit/matchers.rb +87 -40
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 093d792efab35a52d2323239c1a743e67e6d9e8e
|
4
|
+
data.tar.gz: 114b33b8bd33f2fcffd816d01ac7370dc47cc3e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24076c702f7f4cc4b9c0eaa880400c773df365b5459763fbd5cb5a84194fe15ee03864c05a18a0f4d6f3e834f28dc8a42184f3ac602fd346dbd25062b22ff6e2
|
7
|
+
data.tar.gz: b51fb79d247ff289cf108b99b991451e02e24cb9ee29c423f76203564593919e353d894d4d9707bf8bf2ce450320aff03a1507e80870e959b6139f5fd50c8392
|
data/lib/pundit/matchers.rb
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
require 'rspec/core'
|
2
|
+
require 'pundit/matchers/configuration'
|
2
3
|
|
3
4
|
module Pundit
|
4
5
|
module Matchers
|
6
|
+
class << self
|
7
|
+
def configure
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
def configuration
|
12
|
+
@configuration ||= Pundit::Matchers::Configuration.new
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
5
16
|
RSpec::Matchers.define :forbid_action do |action, *args|
|
6
17
|
match do |policy|
|
7
18
|
if args.any?
|
@@ -12,13 +23,15 @@ module Pundit
|
|
12
23
|
end
|
13
24
|
|
14
25
|
failure_message do |policy|
|
15
|
-
"#{policy.class} does not forbid #{action} for "
|
16
|
-
|
26
|
+
"#{policy.class} does not forbid #{action} for " +
|
27
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
28
|
+
.inspect + '.'
|
17
29
|
end
|
18
30
|
|
19
31
|
failure_message_when_negated do |policy|
|
20
|
-
"#{policy.class} does not permit #{action} for "
|
21
|
-
|
32
|
+
"#{policy.class} does not permit #{action} for " +
|
33
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
34
|
+
.inspect + '.'
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
@@ -38,20 +51,24 @@ module Pundit
|
|
38
51
|
'specified when using the forbid_actions matcher.'
|
39
52
|
|
40
53
|
failure_message do |policy|
|
41
|
-
if actions.count
|
54
|
+
if actions.count.zero?
|
42
55
|
zero_actions_failure_message
|
43
56
|
else
|
44
57
|
"#{policy.class} expected to forbid #{actions}, but allowed " \
|
45
|
-
"#{allowed_actions} for
|
58
|
+
"#{allowed_actions} for " +
|
59
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
60
|
+
.inspect + '.'
|
46
61
|
end
|
47
62
|
end
|
48
63
|
|
49
64
|
failure_message_when_negated do |policy|
|
50
|
-
if actions.count
|
65
|
+
if actions.count.zero?
|
51
66
|
zero_actions_failure_message
|
52
67
|
else
|
53
68
|
"#{policy.class} expected to permit #{actions}, but forbade " \
|
54
|
-
"#{allowed_actions} for
|
69
|
+
"#{allowed_actions} for " +
|
70
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
71
|
+
.inspect + '.'
|
55
72
|
end
|
56
73
|
end
|
57
74
|
end
|
@@ -62,13 +79,15 @@ module Pundit
|
|
62
79
|
end
|
63
80
|
|
64
81
|
failure_message do |policy|
|
65
|
-
"#{policy.class} does not forbid the edit or update action for "
|
66
|
-
|
82
|
+
"#{policy.class} does not forbid the edit or update action for " +
|
83
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
84
|
+
.inspect + '.'
|
67
85
|
end
|
68
86
|
|
69
87
|
failure_message_when_negated do |policy|
|
70
|
-
"#{policy.class} does not permit the edit or update action for "
|
71
|
-
|
88
|
+
"#{policy.class} does not permit the edit or update action for " +
|
89
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
90
|
+
.inspect + '.'
|
72
91
|
end
|
73
92
|
end
|
74
93
|
|
@@ -89,10 +108,14 @@ module Pundit
|
|
89
108
|
if defined? @action
|
90
109
|
"#{policy.class} does not forbid the mass assignment of the " \
|
91
110
|
"#{attribute} attribute, when authorising the #{@action} action, " \
|
92
|
-
|
111
|
+
'for ' +
|
112
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
113
|
+
.inspect + '.'
|
93
114
|
else
|
94
115
|
"#{policy.class} does not forbid the mass assignment of the " \
|
95
|
-
"#{attribute} attribute for
|
116
|
+
"#{attribute} attribute for " +
|
117
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
118
|
+
.inspect + '.'
|
96
119
|
end
|
97
120
|
end
|
98
121
|
|
@@ -100,10 +123,14 @@ module Pundit
|
|
100
123
|
if defined? @action
|
101
124
|
"#{policy.class} does not permit the mass assignment of the " \
|
102
125
|
"#{attribute} attribute, when authorising the #{@action} action, " \
|
103
|
-
|
126
|
+
'for ' +
|
127
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
128
|
+
.inspect + '.'
|
104
129
|
else
|
105
130
|
"#{policy.class} does not permit the mass assignment of the " \
|
106
|
-
"#{attribute} attribute for
|
131
|
+
"#{attribute} attribute for " +
|
132
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
133
|
+
.inspect + '.'
|
107
134
|
end
|
108
135
|
end
|
109
136
|
end
|
@@ -114,13 +141,15 @@ module Pundit
|
|
114
141
|
end
|
115
142
|
|
116
143
|
failure_message do |policy|
|
117
|
-
"#{policy.class} does not forbid the new or create action for "
|
118
|
-
|
144
|
+
"#{policy.class} does not forbid the new or create action for " +
|
145
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
146
|
+
.inspect + '.'
|
119
147
|
end
|
120
148
|
|
121
149
|
failure_message_when_negated do |policy|
|
122
|
-
"#{policy.class} does not permit the new or create action for "
|
123
|
-
|
150
|
+
"#{policy.class} does not permit the new or create action for " +
|
151
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
152
|
+
.inspect + '.'
|
124
153
|
end
|
125
154
|
end
|
126
155
|
|
@@ -134,13 +163,15 @@ module Pundit
|
|
134
163
|
end
|
135
164
|
|
136
165
|
failure_message do |policy|
|
137
|
-
"#{policy.class} does not permit #{action} for "
|
138
|
-
|
166
|
+
"#{policy.class} does not permit #{action} for " +
|
167
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
168
|
+
.inspect + '.'
|
139
169
|
end
|
140
170
|
|
141
171
|
failure_message_when_negated do |policy|
|
142
|
-
"#{policy.class} does not forbid #{action} for "
|
143
|
-
|
172
|
+
"#{policy.class} does not forbid #{action} for " +
|
173
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
174
|
+
.inspect + '.'
|
144
175
|
end
|
145
176
|
end
|
146
177
|
|
@@ -159,20 +190,24 @@ module Pundit
|
|
159
190
|
'when using the permit_actions matcher.'
|
160
191
|
|
161
192
|
failure_message do |policy|
|
162
|
-
if actions.count
|
193
|
+
if actions.count.zero?
|
163
194
|
zero_actions_failure_message
|
164
195
|
else
|
165
196
|
"#{policy.class} expected to permit #{actions}, but forbade " \
|
166
|
-
"#{forbidden_actions} for
|
197
|
+
"#{forbidden_actions} for " +
|
198
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
199
|
+
.inspect + '.'
|
167
200
|
end
|
168
201
|
end
|
169
202
|
|
170
203
|
failure_message_when_negated do |policy|
|
171
|
-
if actions.count
|
204
|
+
if actions.count.zero?
|
172
205
|
zero_actions_failure_message
|
173
206
|
else
|
174
207
|
"#{policy.class} expected to forbid #{actions}, but allowed " \
|
175
|
-
"#{forbidden_actions} for
|
208
|
+
"#{forbidden_actions} for " +
|
209
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
210
|
+
.inspect + '.'
|
176
211
|
end
|
177
212
|
end
|
178
213
|
end
|
@@ -183,13 +218,15 @@ module Pundit
|
|
183
218
|
end
|
184
219
|
|
185
220
|
failure_message do |policy|
|
186
|
-
"#{policy.class} does not permit the edit or update action for "
|
187
|
-
|
221
|
+
"#{policy.class} does not permit the edit or update action for " +
|
222
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
223
|
+
.inspect + '.'
|
188
224
|
end
|
189
225
|
|
190
226
|
failure_message_when_negated do |policy|
|
191
|
-
"#{policy.class} does not forbid the edit or update action for "
|
192
|
-
|
227
|
+
"#{policy.class} does not forbid the edit or update action for " +
|
228
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
229
|
+
.inspect + '.'
|
193
230
|
end
|
194
231
|
end
|
195
232
|
|
@@ -210,10 +247,14 @@ module Pundit
|
|
210
247
|
if defined? @action
|
211
248
|
"#{policy.class} does not permit the mass assignment of the " \
|
212
249
|
"#{attribute} attribute, when authorising the #{@action} action, " \
|
213
|
-
|
250
|
+
'for ' +
|
251
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
252
|
+
.inspect + '.'
|
214
253
|
else
|
215
254
|
"#{policy.class} does not permit the mass assignment of the " \
|
216
|
-
"#{attribute} attribute for
|
255
|
+
"#{attribute} attribute for " +
|
256
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
257
|
+
.inspect + '.'
|
217
258
|
end
|
218
259
|
end
|
219
260
|
|
@@ -221,10 +262,14 @@ module Pundit
|
|
221
262
|
if defined? @action
|
222
263
|
"#{policy.class} does not forbid the mass assignment of the " \
|
223
264
|
"#{attribute} attribute, when authorising the #{@action} action, " \
|
224
|
-
|
265
|
+
'for ' +
|
266
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
267
|
+
.inspect + '.'
|
225
268
|
else
|
226
269
|
"#{policy.class} does not forbid the mass assignment of the " \
|
227
|
-
"#{attribute} attribute for
|
270
|
+
"#{attribute} attribute for " +
|
271
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
272
|
+
.inspect + '.'
|
228
273
|
end
|
229
274
|
end
|
230
275
|
end
|
@@ -235,13 +280,15 @@ module Pundit
|
|
235
280
|
end
|
236
281
|
|
237
282
|
failure_message do |policy|
|
238
|
-
"#{policy.class} does not permit the new or create action for "
|
239
|
-
|
283
|
+
"#{policy.class} does not permit the new or create action for " +
|
284
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
285
|
+
.inspect + '.'
|
240
286
|
end
|
241
287
|
|
242
288
|
failure_message_when_negated do |policy|
|
243
|
-
"#{policy.class} does not forbid the new or create action for "
|
244
|
-
|
289
|
+
"#{policy.class} does not forbid the new or create action for " +
|
290
|
+
policy.public_send(Pundit::Matchers.configuration.user_alias)
|
291
|
+
.inspect + '.'
|
245
292
|
end
|
246
293
|
end
|
247
294
|
end
|
metadata
CHANGED
@@ -1,49 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Alley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rspec-rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.1'
|
20
17
|
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
19
|
+
version: 3.0.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '1.1'
|
30
24
|
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
26
|
+
version: 3.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: pundit
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.1'
|
37
34
|
- - ">="
|
38
35
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
type: :
|
36
|
+
version: 1.1.0
|
37
|
+
type: :development
|
41
38
|
prerelease: false
|
42
39
|
version_requirements: !ruby/object:Gem::Requirement
|
43
40
|
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '1.1'
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
46
|
+
version: 1.1.0
|
47
47
|
description: A set of RSpec matchers for testing Pundit authorisation policies
|
48
48
|
email: chris@chrisalley.info
|
49
49
|
executables: []
|