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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pundit/matchers.rb +10 -171
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c237783c9720f52b37ead7abf55f5c383107d4bb
4
- data.tar.gz: 1e7f173871d4460b1124584cc2b9e6b522cf6251
3
+ metadata.gz: 184a315de85608de9c016f604a5a82bd507c8aee
4
+ data.tar.gz: 25996c2bd9a7ca4bcb7d749eeb88048d80a5b782
5
5
  SHA512:
6
- metadata.gz: 37abbbf51d6f80013ed6e1a6a59b38aa60a89f6ef3ea4e75e8073e88180dcc7c959669b7e45ffd6f3106f56ed8d78299d6483f1671c57523650cb6f600100680
7
- data.tar.gz: 1ce22d083a336dbb4934bcd329a652038fc96376510e40695efc47805e2823674467586835109bab06f8990717cab9bbfbee27d36a9b3d7dacdc65bb6ab3bd8f
6
+ metadata.gz: 6a1fdcc1a8ab94bb89309a135141270553c8ac26c9575696cd25b373325d08f9d75a9e9f27b2a6ed5db3fcc44d7794efb6a83beb602c0300b024e2cb123dd842
7
+ data.tar.gz: 6c3b14d119c642c5464e0dd2bdffb2d216445070b0dd8e47b98178d1bae0d4feacffb2af7da4ff1644886498555f6d8c34b2b26c7ee7a7723e03b82730c4994f
@@ -1,176 +1,15 @@
1
1
  require 'rspec/core'
2
2
 
3
- module Pundit
4
- module Matchers
5
- RSpec::Matchers.define :permit_action do |action|
6
- match do |policy|
7
- policy.public_send("#{action}?")
8
- end
9
-
10
- failure_message do |policy|
11
- "#{policy.class} does not permit #{action} on #{policy.record} for " \
12
- "#{policy.user.inspect}."
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.1.0
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: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pundit