pundit-matchers 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pundit/matchers.rb +18 -28
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 641ea95570e02c1afd85001023242ff59b363e78
4
- data.tar.gz: dcbca06d54b69c95faaec2f9df13e266dd44375f
3
+ metadata.gz: fa9d9639180168e0aa248c00f916e8711b0e82a3
4
+ data.tar.gz: 2e70263fd7ca377531a0c34e6136dc0e4ed9f80d
5
5
  SHA512:
6
- metadata.gz: 7ad50adae39b364ac80520e59afdfda56165ff6d21410f2153d8362a856fedc1e2d32fe42e838210e80e3d59d9f3954d7f0176eb8a49c7f5cb731aa9501e6446
7
- data.tar.gz: 685d0b7571579ab06b7e8e9ad70b014534a15d0ccac22813098090da96d76450fcddf1534a75da906b2a6635421bc598b6aad8886ce02be434a8be34243e9de5
6
+ metadata.gz: 5a5ebc0298d666b8b19884710386fe194f114acd2e7724468286032f516f9a522a13418baba5c5b0e93294000dbbe1f190a0b20e5a1646537ffe5aed28eab0fd
7
+ data.tar.gz: c2e2e029245a9e6d52b200905653a9acb092ba23abe481bc1f686364bae5171eeeebc580dc379cad9004f93db9925864579d862f9b551971bc8e43c3f019e67b
@@ -26,28 +26,24 @@ module Pundit
26
26
  RSpec::Matchers.define :forbid_actions do |actions|
27
27
  match do |policy|
28
28
  return false if actions.count < 2
29
- actions.each do |action|
30
- return false if policy.public_send("#{action}?")
29
+ @allowed_actions = actions.select do |action|
30
+ policy.public_send("#{action}?")
31
31
  end
32
- true
32
+ @allowed_actions.empty?
33
33
  end
34
34
 
35
+ attr_reader :allowed_actions
36
+
35
37
  zero_actions_failure_message = 'At least two actions must be ' \
36
38
  'specified when using the forbid_actions matcher.'
37
39
 
38
- one_action_failure_message = 'More than one action must be specified ' \
39
- 'when using the forbid_actions matcher. To test a single action, use ' \
40
- 'forbid_action instead.'
41
-
42
40
  failure_message do |policy|
43
41
  case actions.count
44
42
  when 0
45
43
  zero_actions_failure_message
46
- when 1
47
- one_action_failure_message
48
44
  else
49
- "#{policy.class} does not forbid #{actions} for " \
50
- "#{policy.user.inspect}."
45
+ "#{policy.class} expected to forbid #{actions}, but allowed " \
46
+ "#{allowed_actions} for #{policy.user.inspect}."
51
47
  end
52
48
  end
53
49
 
@@ -55,11 +51,9 @@ module Pundit
55
51
  case actions.count
56
52
  when 0
57
53
  zero_actions_failure_message
58
- when 1
59
- one_action_failure_message
60
54
  else
61
- "#{policy.class} does not permit #{actions} for " \
62
- "#{policy.user.inspect}."
55
+ "#{policy.class} expected to permit #{actions}, but forbade " \
56
+ "#{allowed_actions} for #{policy.user.inspect}."
63
57
  end
64
58
  end
65
59
  end
@@ -155,28 +149,24 @@ module Pundit
155
149
  RSpec::Matchers.define :permit_actions do |actions|
156
150
  match do |policy|
157
151
  return false if actions.count < 2
158
- actions.each do |action|
159
- return false unless policy.public_send("#{action}?")
152
+ @forbidden_actions = actions.reject do |action|
153
+ policy.public_send("#{action}?")
160
154
  end
161
- true
155
+ @forbidden_actions.empty?
162
156
  end
163
157
 
158
+ attr_reader :forbidden_actions
159
+
164
160
  zero_actions_failure_message = 'At least two actions must be ' \
165
161
  'specified when using the permit_actions matcher.'
166
162
 
167
- one_action_failure_message = 'More than one action must be specified ' \
168
- 'when using the permit_actions matcher. To test a single action, use ' \
169
- 'permit_action instead.'
170
-
171
163
  failure_message do |policy|
172
164
  case actions.count
173
165
  when 0
174
166
  zero_actions_failure_message
175
- when 1
176
- one_action_failure_message
177
167
  else
178
- "#{policy.class} does not permit #{actions} for " \
179
- "#{policy.user.inspect}."
168
+ "#{policy.class} expected to permit #{actions}, but forbade " \
169
+ "#{forbidden_actions} for #{policy.user.inspect}."
180
170
  end
181
171
  end
182
172
 
@@ -187,8 +177,8 @@ module Pundit
187
177
  when 1
188
178
  one_action_failure_message
189
179
  else
190
- "#{policy.class} does not forbid #{actions} for " \
191
- "#{policy.user.inspect}."
180
+ "#{policy.class} expected to forbid #{actions}, but allowed " \
181
+ "#{forbidden_actions} for #{policy.user.inspect}."
192
182
  end
193
183
  end
194
184
  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.3.1
4
+ version: 1.4.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: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pundit
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  version: '0'
72
72
  requirements: []
73
73
  rubyforge_project:
74
- rubygems_version: 2.5.1
74
+ rubygems_version: 2.6.14
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: RSpec matchers for Pundit policies