pundit-matchers 1.0.2 → 1.1.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 +66 -26
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c237783c9720f52b37ead7abf55f5c383107d4bb
|
4
|
+
data.tar.gz: 1e7f173871d4460b1124584cc2b9e6b522cf6251
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37abbbf51d6f80013ed6e1a6a59b38aa60a89f6ef3ea4e75e8073e88180dcc7c959669b7e45ffd6f3106f56ed8d78299d6483f1671c57523650cb6f600100680
|
7
|
+
data.tar.gz: 1ce22d083a336dbb4934bcd329a652038fc96376510e40695efc47805e2823674467586835109bab06f8990717cab9bbfbee27d36a9b3d7dacdc65bb6ab3bd8f
|
data/lib/pundit/matchers.rb
CHANGED
@@ -8,61 +8,81 @@ module Pundit
|
|
8
8
|
end
|
9
9
|
|
10
10
|
failure_message do |policy|
|
11
|
-
"#{policy.class} does not permit #{action} on #{policy.record} for "
|
11
|
+
"#{policy.class} does not permit #{action} on #{policy.record} for " \
|
12
12
|
"#{policy.user.inspect}."
|
13
13
|
end
|
14
14
|
|
15
15
|
failure_message_when_negated do |policy|
|
16
|
-
"#{policy.class} does not forbid #{action} on #{policy.record} for "
|
16
|
+
"#{policy.class} does not forbid #{action} on #{policy.record} for " \
|
17
17
|
"#{policy.user.inspect}."
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
RSpec::Matchers.define :permit_new_and_create_actions do
|
22
22
|
match do |policy|
|
23
|
-
policy.new?
|
23
|
+
policy.new? && policy.create?
|
24
24
|
end
|
25
25
|
|
26
26
|
failure_message do |policy|
|
27
|
-
"#{policy.class} does not permit the new or create action on "
|
27
|
+
"#{policy.class} does not permit the new or create action on " \
|
28
28
|
"#{policy.record} for #{policy.user.inspect}."
|
29
29
|
end
|
30
30
|
|
31
31
|
failure_message_when_negated do |policy|
|
32
|
-
"#{policy.class} does not forbid the new or create action on "
|
32
|
+
"#{policy.class} does not forbid the new or create action on " \
|
33
33
|
"#{policy.record} for #{policy.user.inspect}."
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
RSpec::Matchers.define :permit_edit_and_update_actions do
|
38
38
|
match do |policy|
|
39
|
-
policy.edit?
|
39
|
+
policy.edit? && policy.update?
|
40
40
|
end
|
41
41
|
|
42
42
|
failure_message do |policy|
|
43
|
-
"#{policy.class} does not permit the edit or update action on "
|
43
|
+
"#{policy.class} does not permit the edit or update action on " \
|
44
44
|
"#{policy.record} for #{policy.user.inspect}."
|
45
45
|
end
|
46
46
|
|
47
47
|
failure_message_when_negated do |policy|
|
48
|
-
"#{policy.class} does not forbid the edit or update action on "
|
48
|
+
"#{policy.class} does not forbid the edit or update action on " \
|
49
49
|
"#{policy.record} for #{policy.user.inspect}."
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
RSpec::Matchers.define :permit_mass_assignment_of do |attribute|
|
54
54
|
match do |policy|
|
55
|
-
|
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
|
56
64
|
end
|
57
65
|
|
58
66
|
failure_message do |policy|
|
59
|
-
|
60
|
-
"#{
|
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
|
61
75
|
end
|
62
76
|
|
63
77
|
failure_message_when_negated do |policy|
|
64
|
-
|
65
|
-
"#{
|
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
|
66
86
|
end
|
67
87
|
end
|
68
88
|
|
@@ -72,61 +92,81 @@ module Pundit
|
|
72
92
|
end
|
73
93
|
|
74
94
|
failure_message do |policy|
|
75
|
-
"#{policy.class} does not forbid #{action} on #{policy.record} for "
|
95
|
+
"#{policy.class} does not forbid #{action} on #{policy.record} for " \
|
76
96
|
"#{policy.user.inspect}."
|
77
97
|
end
|
78
98
|
|
79
99
|
failure_message_when_negated do |policy|
|
80
|
-
"#{policy.class} does not permit #{action} on #{policy.record} for "
|
100
|
+
"#{policy.class} does not permit #{action} on #{policy.record} for " \
|
81
101
|
"#{policy.user.inspect}."
|
82
102
|
end
|
83
103
|
end
|
84
104
|
|
85
105
|
RSpec::Matchers.define :forbid_new_and_create_actions do
|
86
106
|
match do |policy|
|
87
|
-
!policy.new?
|
107
|
+
!policy.new? && !policy.create?
|
88
108
|
end
|
89
109
|
|
90
110
|
failure_message do |policy|
|
91
|
-
"#{policy.class} does not forbid the new or create action on "
|
111
|
+
"#{policy.class} does not forbid the new or create action on " \
|
92
112
|
"#{policy.record} for #{policy.user.inspect}."
|
93
113
|
end
|
94
114
|
|
95
115
|
failure_message_when_negated do |policy|
|
96
|
-
"#{policy.class} does not permit the new or create action on "
|
116
|
+
"#{policy.class} does not permit the new or create action on " \
|
97
117
|
"#{policy.record} for #{policy.user.inspect}."
|
98
118
|
end
|
99
119
|
end
|
100
120
|
|
101
121
|
RSpec::Matchers.define :forbid_edit_and_update_actions do
|
102
122
|
match do |policy|
|
103
|
-
!policy.edit?
|
123
|
+
!policy.edit? && !policy.update?
|
104
124
|
end
|
105
125
|
|
106
126
|
failure_message do |policy|
|
107
|
-
"#{policy.class} does not forbid the edit or update action on "
|
127
|
+
"#{policy.class} does not forbid the edit or update action on " \
|
108
128
|
"#{policy.record} for #{policy.user.inspect}."
|
109
129
|
end
|
110
130
|
|
111
131
|
failure_message_when_negated do |policy|
|
112
|
-
"#{policy.class} does not permit the edit or update action on "
|
132
|
+
"#{policy.class} does not permit the edit or update action on " \
|
113
133
|
"#{policy.record} for #{policy.user.inspect}."
|
114
134
|
end
|
115
135
|
end
|
116
136
|
|
117
137
|
RSpec::Matchers.define :forbid_mass_assignment_of do |attribute|
|
118
138
|
match do |policy|
|
119
|
-
|
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
|
120
148
|
end
|
121
149
|
|
122
150
|
failure_message do |policy|
|
123
|
-
|
124
|
-
"#{
|
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
|
125
159
|
end
|
126
160
|
|
127
161
|
failure_message_when_negated do |policy|
|
128
|
-
|
129
|
-
"#{
|
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
|
130
170
|
end
|
131
171
|
end
|
132
172
|
end
|
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.0
|
4
|
+
version: 1.1.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: 2016-
|
11
|
+
date: 2016-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pundit
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.1'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.1.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '1.
|
29
|
+
version: '1.1'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.
|
32
|
+
version: 1.1.0
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: rspec-rails
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|