pundit-matchers 1.1.0 → 1.2.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 +10 -171
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 184a315de85608de9c016f604a5a82bd507c8aee
|
4
|
+
data.tar.gz: 25996c2bd9a7ca4bcb7d749eeb88048d80a5b782
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a1fdcc1a8ab94bb89309a135141270553c8ac26c9575696cd25b373325d08f9d75a9e9f27b2a6ed5db3fcc44d7794efb6a83beb602c0300b024e2cb123dd842
|
7
|
+
data.tar.gz: 6c3b14d119c642c5464e0dd2bdffb2d216445070b0dd8e47b98178d1bae0d4feacffb2af7da4ff1644886498555f6d8c34b2b26c7ee7a7723e03b82730c4994f
|
data/lib/pundit/matchers.rb
CHANGED
@@ -1,176 +1,15 @@
|
|
1
1
|
require 'rspec/core'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
failure_message_when_negated do |policy|
|
16
|
-
"#{policy.class} does not forbid #{action} on #{policy.record} for " \
|
17
|
-
"#{policy.user.inspect}."
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
RSpec::Matchers.define :permit_new_and_create_actions do
|
22
|
-
match do |policy|
|
23
|
-
policy.new? && policy.create?
|
24
|
-
end
|
25
|
-
|
26
|
-
failure_message do |policy|
|
27
|
-
"#{policy.class} does not permit the new or create action on " \
|
28
|
-
"#{policy.record} for #{policy.user.inspect}."
|
29
|
-
end
|
30
|
-
|
31
|
-
failure_message_when_negated do |policy|
|
32
|
-
"#{policy.class} does not forbid the new or create action on " \
|
33
|
-
"#{policy.record} for #{policy.user.inspect}."
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
RSpec::Matchers.define :permit_edit_and_update_actions do
|
38
|
-
match do |policy|
|
39
|
-
policy.edit? && policy.update?
|
40
|
-
end
|
41
|
-
|
42
|
-
failure_message do |policy|
|
43
|
-
"#{policy.class} does not permit the edit or update action on " \
|
44
|
-
"#{policy.record} for #{policy.user.inspect}."
|
45
|
-
end
|
46
|
-
|
47
|
-
failure_message_when_negated do |policy|
|
48
|
-
"#{policy.class} does not forbid the edit or update action on " \
|
49
|
-
"#{policy.record} for #{policy.user.inspect}."
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
RSpec::Matchers.define :permit_mass_assignment_of do |attribute|
|
54
|
-
match do |policy|
|
55
|
-
if @action
|
56
|
-
policy.send("permitted_attributes_for_#{@action}").include? attribute
|
57
|
-
else
|
58
|
-
policy.permitted_attributes.include? attribute
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
chain :for_action do |action|
|
63
|
-
@action = action
|
64
|
-
end
|
65
|
-
|
66
|
-
failure_message do |policy|
|
67
|
-
if @action
|
68
|
-
"#{policy.class} does not permit the mass assignment of the " \
|
69
|
-
"#{attribute} attribute, when authorising the #{@action} action, " \
|
70
|
-
"for #{policy.user.inspect}."
|
71
|
-
else
|
72
|
-
"#{policy.class} does not permit the mass assignment of the " \
|
73
|
-
"#{attribute} attribute for #{policy.user.inspect}."
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
failure_message_when_negated do |policy|
|
78
|
-
if @action
|
79
|
-
"#{policy.class} does not forbid the mass assignment of the " \
|
80
|
-
"#{attribute} attribute, when authorising the #{@action} action, " \
|
81
|
-
"for #{policy.user.inspect}."
|
82
|
-
else
|
83
|
-
"#{policy.class} does not forbid the mass assignment of the " \
|
84
|
-
"#{attribute} attribute for #{policy.user.inspect}."
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
RSpec::Matchers.define :forbid_action do |action|
|
90
|
-
match do |policy|
|
91
|
-
!policy.public_send("#{action}?")
|
92
|
-
end
|
93
|
-
|
94
|
-
failure_message do |policy|
|
95
|
-
"#{policy.class} does not forbid #{action} on #{policy.record} for " \
|
96
|
-
"#{policy.user.inspect}."
|
97
|
-
end
|
98
|
-
|
99
|
-
failure_message_when_negated do |policy|
|
100
|
-
"#{policy.class} does not permit #{action} on #{policy.record} for " \
|
101
|
-
"#{policy.user.inspect}."
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
RSpec::Matchers.define :forbid_new_and_create_actions do
|
106
|
-
match do |policy|
|
107
|
-
!policy.new? && !policy.create?
|
108
|
-
end
|
109
|
-
|
110
|
-
failure_message do |policy|
|
111
|
-
"#{policy.class} does not forbid the new or create action on " \
|
112
|
-
"#{policy.record} for #{policy.user.inspect}."
|
113
|
-
end
|
114
|
-
|
115
|
-
failure_message_when_negated do |policy|
|
116
|
-
"#{policy.class} does not permit the new or create action on " \
|
117
|
-
"#{policy.record} for #{policy.user.inspect}."
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
RSpec::Matchers.define :forbid_edit_and_update_actions do
|
122
|
-
match do |policy|
|
123
|
-
!policy.edit? && !policy.update?
|
124
|
-
end
|
125
|
-
|
126
|
-
failure_message do |policy|
|
127
|
-
"#{policy.class} does not forbid the edit or update action on " \
|
128
|
-
"#{policy.record} for #{policy.user.inspect}."
|
129
|
-
end
|
130
|
-
|
131
|
-
failure_message_when_negated do |policy|
|
132
|
-
"#{policy.class} does not permit the edit or update action on " \
|
133
|
-
"#{policy.record} for #{policy.user.inspect}."
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
RSpec::Matchers.define :forbid_mass_assignment_of do |attribute|
|
138
|
-
match do |policy|
|
139
|
-
if @action
|
140
|
-
policy.send("permitted_attributes_for_#{@action}").exclude? attribute
|
141
|
-
else
|
142
|
-
policy.permitted_attributes.exclude? attribute
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
chain :for_action do |action|
|
147
|
-
@action = action
|
148
|
-
end
|
149
|
-
|
150
|
-
failure_message do |policy|
|
151
|
-
if @action
|
152
|
-
"#{policy.class} does not forbid the mass assignment of the " \
|
153
|
-
"#{attribute} attribute, when authorising the #{@action} action, " \
|
154
|
-
"for #{policy.user.inspect}."
|
155
|
-
else
|
156
|
-
"#{policy.class} does not forbid the mass assignment of the " \
|
157
|
-
"#{attribute} attribute for #{policy.user.inspect}."
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
failure_message_when_negated do |policy|
|
162
|
-
if @action
|
163
|
-
"#{policy.class} does not permit the mass assignment of the " \
|
164
|
-
"#{attribute} attribute, when authorising the #{@action} action, " \
|
165
|
-
"for #{policy.user.inspect}."
|
166
|
-
else
|
167
|
-
"#{policy.class} does not permit the mass assignment of the " \
|
168
|
-
"#{attribute} attribute for #{policy.user.inspect}."
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
3
|
+
require_relative './matchers/forbid_action'
|
4
|
+
require_relative './matchers/forbid_actions'
|
5
|
+
require_relative './matchers/forbid_edit_and_update_actions'
|
6
|
+
require_relative './matchers/forbid_mass_assignment_of'
|
7
|
+
require_relative './matchers/forbid_new_and_create_actions'
|
8
|
+
require_relative './matchers/permit_action'
|
9
|
+
require_relative './matchers/permit_actions'
|
10
|
+
require_relative './matchers/permit_edit_and_update_actions'
|
11
|
+
require_relative './matchers/permit_mass_assignment_of'
|
12
|
+
require_relative './matchers/permit_new_and_create_actions'
|
174
13
|
|
175
14
|
if defined?(Pundit)
|
176
15
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pundit-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.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: 2017-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pundit
|