radius-spec 0.7.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +28 -0
- data/.github/workflows/reviewdog.yml +21 -0
- data/.rubocop.yml +6 -6
- data/CHANGELOG.md +131 -4
- data/Gemfile +1 -3
- data/README.md +5 -6
- data/benchmarks/call_vs_yield.rb +0 -2
- data/benchmarks/cover_vs_include.rb +2 -2
- data/benchmarks/hash_each.rb +305 -0
- data/benchmarks/hash_merge.rb +1 -1
- data/benchmarks/hash_transform.rb +455 -0
- data/benchmarks/style_hash_like_case.rb +285 -0
- data/benchmarks/unfreeze_string.rb +0 -2
- data/bin/bundle +114 -0
- data/common_rubocop.yml +186 -61
- data/common_rubocop_rails.yml +87 -12
- data/lib/radius/spec/model_factory.rb +8 -3
- data/lib/radius/spec/rspec.rb +14 -0
- data/lib/radius/spec/vcr.rb +4 -6
- data/lib/radius/spec/version.rb +1 -1
- data/radius-spec.gemspec +7 -6
- metadata +16 -11
- data/.travis.yml +0 -15
- data/bin/ci-code-review +0 -28
data/common_rubocop.yml
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.7.0
|
3
|
+
# We choose to opt-in to new checks by default. This allows us to update
|
4
|
+
# version by version without having to worry about adding an entry for each
|
5
|
+
# new "enabled by default" check. If we want to jump multiple versions and
|
6
|
+
# wish to be notified of all the enw check, then we'll need to change
|
7
|
+
# `NewCops` to `pending`.
|
8
|
+
NewCops: enable
|
3
9
|
Exclude:
|
4
10
|
# Exclude generated binstubs
|
5
11
|
- 'bin/bundle'
|
@@ -18,6 +24,11 @@ AllCops:
|
|
18
24
|
# Exclude vendored content
|
19
25
|
- 'vendor/**/*'
|
20
26
|
|
27
|
+
# We would like to disallow http for bundler sources and enforce https
|
28
|
+
# as it is more secure.
|
29
|
+
Bundler/InsecureProtocolSource:
|
30
|
+
AllowHttpProtocol: false
|
31
|
+
|
21
32
|
# We prefer outdented access modifiers as we feel they provide demarcation of
|
22
33
|
# the class similar to `rescue` and `ensure` in a method.
|
23
34
|
#
|
@@ -30,6 +41,18 @@ Layout/AccessModifierIndentation:
|
|
30
41
|
similar to `rescue` and `ensure` in a method.
|
31
42
|
EnforcedStyle: outdent
|
32
43
|
|
44
|
+
# This cop checks whether the end keyword of begin is aligned properly.
|
45
|
+
#
|
46
|
+
# Two modes are supported through the EnforcedStyleAlignWith configuration parameter. If it’s set to
|
47
|
+
# begin, the end shall be aligned with the begin keyword. We chose this to be consistent with our if
|
48
|
+
# statement styles, if you want the end to be aligned with the start of the line just put the begin
|
49
|
+
# on the next line.
|
50
|
+
#
|
51
|
+
# Configuration parameters: EnforcedStyleAlignWith
|
52
|
+
# SupportedStyles: start_of_line, begin
|
53
|
+
Layout/BeginEndAlignment:
|
54
|
+
EnforcedStyleAlignWith: begin
|
55
|
+
|
33
56
|
# Rubocop 0.60.0 changed how it handled value alignments in this cop. This
|
34
57
|
# breaks our preference for wanting keys to be aligned, but allowing values to
|
35
58
|
# either use the `key` or `table` style:
|
@@ -56,7 +79,7 @@ Layout/AccessModifierIndentation:
|
|
56
79
|
# SupportedHashRocketStyles: key, separator, table
|
57
80
|
# SupportedColonStyles: key, separator, table
|
58
81
|
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
|
59
|
-
Layout/
|
82
|
+
Layout/HashAlignment:
|
60
83
|
Enabled: true
|
61
84
|
EnforcedHashRocketStyle: key
|
62
85
|
EnforcedColonStyle: key
|
@@ -82,17 +105,43 @@ Layout/BlockAlignment:
|
|
82
105
|
#
|
83
106
|
# TODO: At some point this is split into both Layout/FirstArgumentIndentation
|
84
107
|
# and Layout/FirstParameterIndentation
|
85
|
-
Layout/
|
108
|
+
Layout/FirstArgumentIndentation:
|
86
109
|
Enabled: false
|
87
110
|
|
88
|
-
#
|
89
|
-
#
|
90
|
-
# alternatives; even for Rails app.
|
111
|
+
# We generally prefer to use the default line length of 80. Though sometimes
|
112
|
+
# we just need a little extra space because it makes it easier to read.
|
91
113
|
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
-
|
114
|
+
# The only way to disable Rubocop for a single line is either to wrap the line
|
115
|
+
# with two comments or append the disable comment to the end of the line. For
|
116
|
+
# guard clauses, we tend to prefer trailing comments to avoid adding two lines
|
117
|
+
# just to disable a cop on one line.
|
118
|
+
#
|
119
|
+
# Sometimes comments include ASCII diagrams, flow charts, etc. These cannot
|
120
|
+
# always be reformatted to fit within the 80 column limit. Also, we write most
|
121
|
+
# comments in markdown format. Rubocop isn't very good at understanding when
|
122
|
+
# the line is long because of a URL in a markdown link. Instead of requiring
|
123
|
+
# additional comments to turn this cop off for comments we ignore any long
|
124
|
+
# lines which are only comments.
|
125
|
+
#
|
126
|
+
# There are also cases where for one valid reason or another we have a trailing
|
127
|
+
# comment that extends a little too far. We'd like to be able to ignore those
|
128
|
+
# as well. This _attempts_ to do that, however, as this uses simple regular
|
129
|
+
# expressions we can only attempt to match so much. We probably should change
|
130
|
+
# this for a node pattern matcher in the future.
|
131
|
+
#
|
132
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes,
|
133
|
+
# IgnoreCopDirectives, IgnoredPatterns.
|
134
|
+
# URISchemes: http, https
|
135
|
+
Layout/LineLength:
|
136
|
+
IgnoreCopDirectives: true
|
137
|
+
IgnoredPatterns:
|
138
|
+
# Leading comments
|
139
|
+
- '\A\s*#'
|
140
|
+
# Attempt at trailing comments
|
141
|
+
- '\A.{1,78}\s#\s.*\z'
|
142
|
+
Max: 100
|
143
|
+
Exclude:
|
144
|
+
- '**/*.gemspec'
|
96
145
|
|
97
146
|
# We tend to indent multi-line operation statements. I think this is because it
|
98
147
|
# tends to be the default style auto-formatted by VIM (which many of us use).
|
@@ -123,6 +172,18 @@ Layout/MultilineOperationIndentation:
|
|
123
172
|
# }.to change {
|
124
173
|
# object.state
|
125
174
|
# }
|
175
|
+
#
|
176
|
+
# WARNING TO FUTURE READERS (future being after 2021-12-10):
|
177
|
+
# We tried to allowlist certain methods using the IgnoredMethods option (introduced 1.13.0),
|
178
|
+
# and Rubocop successfully ignored `change` and `not_change` constructions, but it flag false
|
179
|
+
# positives against code like
|
180
|
+
#
|
181
|
+
# expect { something }
|
182
|
+
# .to enqueue_job(SomeJobClass)
|
183
|
+
# .with { custom expectations about the enqueued payload }
|
184
|
+
#
|
185
|
+
# no matter what combination of `enqueue_job` and `with` we tried to add to the IgnoredMethods
|
186
|
+
# array. We suspect the AST matching is somewhat half-baked.
|
126
187
|
Lint/AmbiguousBlockAssociation:
|
127
188
|
Exclude:
|
128
189
|
- 'spec/**/*_spec.rb'
|
@@ -152,6 +213,10 @@ Lint/HeredocMethodCallPosition:
|
|
152
213
|
Lint/InheritException:
|
153
214
|
EnforcedStyle: standard_error
|
154
215
|
|
216
|
+
# Make developers explain themselves in a comment if they want their rescue block to do nothing.
|
217
|
+
Lint/SuppressedException:
|
218
|
+
AllowNil: false
|
219
|
+
|
155
220
|
# Often with benchmarking we don't explicitly "use" a variable or return value.
|
156
221
|
# We simply need to perform the operation which generates said value for the
|
157
222
|
# benchmark.
|
@@ -162,70 +227,54 @@ Lint/Void:
|
|
162
227
|
- 'benchmarks/**/*'
|
163
228
|
|
164
229
|
Metrics/AbcSize:
|
165
|
-
|
166
|
-
# following `CountRepeatedAttributes` option. We often find the
|
167
|
-
# multi-references to the same object to be necessary for reability and that
|
168
|
-
# for our team it does not increase complexity.
|
169
|
-
#
|
170
|
-
# CountRepeatedAttributes: false
|
230
|
+
CountRepeatedAttributes: false
|
171
231
|
Max: 17
|
172
232
|
|
173
|
-
# Configuration parameters: CountComments,
|
174
|
-
#
|
233
|
+
# Configuration parameters: CountComments, IgnoredMethods, Max.
|
234
|
+
# IgnoredMethods: refine
|
175
235
|
Metrics/BlockLength:
|
236
|
+
CountAsOne:
|
237
|
+
- 'array'
|
238
|
+
- 'hash'
|
239
|
+
- 'heredoc'
|
176
240
|
Exclude:
|
177
241
|
- '**/Rakefile'
|
178
242
|
- '**/*.rake'
|
179
243
|
- 'spec/spec_helper.rb'
|
180
244
|
- 'spec/**/*_spec.rb'
|
181
245
|
- 'spec/support/model_factories.rb'
|
182
|
-
|
246
|
+
IgnoredMethods:
|
183
247
|
- 'chdir'
|
248
|
+
- 'describe'
|
184
249
|
- 'refine'
|
250
|
+
- 'shared_context'
|
251
|
+
- 'shared_examples'
|
185
252
|
- 'Capybara.register_driver'
|
186
253
|
- 'RSpec.configure'
|
254
|
+
- 'RSpec.describe'
|
255
|
+
- 'RSpec.shared_context'
|
256
|
+
- 'RSpec.shared_examples'
|
187
257
|
- 'VCR.configure'
|
188
258
|
|
189
|
-
# We
|
190
|
-
#
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
# this for a node pattern matcher in the future.
|
209
|
-
#
|
210
|
-
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes,
|
211
|
-
# IgnoreCopDirectives, IgnoredPatterns.
|
212
|
-
# URISchemes: http, https
|
213
|
-
Metrics/LineLength:
|
214
|
-
IgnoreCopDirectives: true
|
215
|
-
IgnoredPatterns:
|
216
|
-
# Leading comments
|
217
|
-
- '\A\s*#'
|
218
|
-
# Attempt at trailing comments
|
219
|
-
- '\A.{1,78}\s#\s.*\z'
|
220
|
-
Max: 100
|
221
|
-
Exclude:
|
222
|
-
- '**/*.gemspec'
|
223
|
-
|
224
|
-
# TODO: Remove this when we get to 0.89.0 as the new default max is 8
|
225
|
-
#
|
226
|
-
# Configuration parameters: IgnoredMethods, Max
|
227
|
-
Metrics/PerceivedComplexity:
|
228
|
-
Max: 8
|
259
|
+
# We want length related code metrics to count Hashs, Arrays, and
|
260
|
+
# Heredocs as one "line"
|
261
|
+
Metrics/ClassLength:
|
262
|
+
CountAsOne:
|
263
|
+
- 'array'
|
264
|
+
- 'hash'
|
265
|
+
- 'heredoc'
|
266
|
+
|
267
|
+
Metrics/ModuleLength:
|
268
|
+
CountAsOne:
|
269
|
+
- 'array'
|
270
|
+
- 'hash'
|
271
|
+
- 'heredoc'
|
272
|
+
|
273
|
+
Metrics/MethodLength:
|
274
|
+
CountAsOne:
|
275
|
+
- 'array'
|
276
|
+
- 'hash'
|
277
|
+
- 'heredoc'
|
229
278
|
|
230
279
|
# This is overly pedantic (only allowing `other` as the parameter name). Ruby
|
231
280
|
# core doesn't follow this consistently either. Looking at several classes
|
@@ -235,6 +284,21 @@ Metrics/PerceivedComplexity:
|
|
235
284
|
Naming/BinaryOperatorParameterName:
|
236
285
|
Enabled: false
|
237
286
|
|
287
|
+
# We don't need this configured just yet, because we dont have any applications on
|
288
|
+
# Ruby 3.1, but pre-emptively, we want to configure this to prefer the explicit style.
|
289
|
+
#
|
290
|
+
# bad
|
291
|
+
# def foo(&)
|
292
|
+
# bar(&)
|
293
|
+
# end
|
294
|
+
|
295
|
+
# good
|
296
|
+
# def foo(&block)
|
297
|
+
# bar(&block)
|
298
|
+
# end
|
299
|
+
Naming/BlockForwarding:
|
300
|
+
EnforcedStyle: explicit
|
301
|
+
|
238
302
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
239
303
|
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
240
304
|
Naming/FileName:
|
@@ -248,14 +312,14 @@ Naming/FileName:
|
|
248
312
|
# `EOF` is a common terminal abbreviate indicating end-of-file. We allow this
|
249
313
|
# for those heredocs which represent "file" text.
|
250
314
|
#
|
251
|
-
# Configuration parameters:
|
252
|
-
#
|
315
|
+
# Configuration parameters: ForbiddenDelimiters.
|
316
|
+
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
253
317
|
Naming/HeredocDelimiterNaming:
|
254
318
|
Details: |
|
255
319
|
|
256
320
|
Use meaningful delimiter names to provide context to the text. The only
|
257
321
|
allowed `EO*` variant if `EOF` which has specific meaning for file content.
|
258
|
-
|
322
|
+
ForbiddenDelimiters:
|
259
323
|
- !ruby/regexp '/(^|\s)(EO[A-EG-Z]{1}|END)(\s|$)/'
|
260
324
|
|
261
325
|
# It is generally a good idea to match the instance variable names with their
|
@@ -324,6 +388,9 @@ Style/AndOr:
|
|
324
388
|
# These days most people have editors which support unicode and other
|
325
389
|
# non-ASCII characters.
|
326
390
|
#
|
391
|
+
# In version 1.21.0, this is disabled by default. We've chosen to leave
|
392
|
+
# it in the config, in case it changes in future versions.
|
393
|
+
#
|
327
394
|
# Configuration parameters: AllowedChars.
|
328
395
|
Style/AsciiComments:
|
329
396
|
Enabled: false
|
@@ -380,6 +447,15 @@ Style/BlockDelimiters:
|
|
380
447
|
- proc
|
381
448
|
- it
|
382
449
|
|
450
|
+
# As a team we prefer the more explicit `def self.method_name` style. We find
|
451
|
+
# the explicitness easier to read and grep for on the CLI.
|
452
|
+
#
|
453
|
+
# Configuration parameters: EnforcedStyle.
|
454
|
+
# SupportedStyles: def_self, self_class
|
455
|
+
Style/ClassMethodsDefinitions:
|
456
|
+
Enabled: true
|
457
|
+
EnforcedStyle: def_self
|
458
|
+
|
383
459
|
# Prefer `Time` over `DateTime`.
|
384
460
|
#
|
385
461
|
# While these are not necessarily interchangeable we prefer `Time`. According
|
@@ -454,6 +530,13 @@ Style/EmptyCaseCondition:
|
|
454
530
|
Style/EmptyMethod:
|
455
531
|
EnforcedStyle: expanded
|
456
532
|
|
533
|
+
# Always require the pragma comment to be true
|
534
|
+
#
|
535
|
+
# Configuration parameters: EnforcedStyle.
|
536
|
+
# SupportedStyles: always, always_true, never
|
537
|
+
Style/FrozenStringLiteralComment:
|
538
|
+
EnforcedStyle: always_true
|
539
|
+
|
457
540
|
# Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
|
458
541
|
# use a consistent mapping style; which generally means using hash rockets:
|
459
542
|
#
|
@@ -474,6 +557,7 @@ Style/HashSyntax:
|
|
474
557
|
Prefer symbol keys using the 1.9 hash syntax. However, when keys are mixed
|
475
558
|
use a consistent mapping style; which generally means using hash rockets.
|
476
559
|
EnforcedStyle: ruby19_no_mixed_keys
|
560
|
+
EnforcedShorthandSyntax: either
|
477
561
|
|
478
562
|
# As part of our semantic style we generally use the literal `-> { }` format to
|
479
563
|
# indicate this is a function with a return value we care about. As this cop
|
@@ -504,6 +588,11 @@ Style/MethodCalledOnDoEndBlock:
|
|
504
588
|
Style/MultilineBlockChain:
|
505
589
|
Enabled: false
|
506
590
|
|
591
|
+
# Disallowing numbered parameter usage because we dont prefer this style.
|
592
|
+
# We would rather name the paramaters to clearly communicate intent.
|
593
|
+
Style/NumberedParameters:
|
594
|
+
EnforcedStyle: disallow
|
595
|
+
|
507
596
|
# Context for this cop is too dependent.
|
508
597
|
#
|
509
598
|
# Often using the numeric comparison is faster. Also, depending on the context
|
@@ -520,6 +609,12 @@ Style/MultilineBlockChain:
|
|
520
609
|
Style/NumericPredicate:
|
521
610
|
Enabled: false
|
522
611
|
|
612
|
+
# As a general rule, we want to be explicit here instead of requiring readers
|
613
|
+
# of our code to know what the default arguments to methods like `#join` and
|
614
|
+
# and `#split` so we disable this cop here.
|
615
|
+
Style/RedundantArgument:
|
616
|
+
Enabled: false
|
617
|
+
|
523
618
|
# In Ruby every method returns a value. Implicitly this is the value of the
|
524
619
|
# last line of the method. This means using `return` is often redundant.
|
525
620
|
# However, there isn't anything inherently wrong about doing so. In fact, in
|
@@ -627,6 +722,20 @@ Style/RescueStandardError:
|
|
627
722
|
Avoid rescuing `Exception` as this may hide system errors.
|
628
723
|
EnforcedStyle: implicit
|
629
724
|
|
725
|
+
# We don't really care which style we use here and would prefer rubocop not
|
726
|
+
# complain about this.
|
727
|
+
Style/SlicingWithRange:
|
728
|
+
Enabled: false
|
729
|
+
|
730
|
+
# We want to turn this cop on so that rubocop can yell at us instead of Aaron
|
731
|
+
# yelling at us.
|
732
|
+
Style/StaticClass:
|
733
|
+
Enabled: true
|
734
|
+
|
735
|
+
# Enable Style/StringChars
|
736
|
+
Style/StringChars:
|
737
|
+
Enabled: true
|
738
|
+
|
630
739
|
# We generally prefer double quotes but many generators use single quotes. We
|
631
740
|
# don't view the performance difference to be all that much so we don't care
|
632
741
|
# if the style is mixed or double quotes are used for static strings.
|
@@ -657,6 +766,13 @@ Style/StringLiteralsInInterpolation:
|
|
657
766
|
Style/SymbolArray:
|
658
767
|
MinSize: 3
|
659
768
|
|
769
|
+
# Allow either
|
770
|
+
# something.do_something(foo, &:bar)
|
771
|
+
# or
|
772
|
+
# something.do_something(foo) { |s| s.bar }
|
773
|
+
Style/SymbolProc:
|
774
|
+
AllowMethodsWithArguments: true
|
775
|
+
|
660
776
|
# When ternaries become complex they can be difficult to read due to increased
|
661
777
|
# cognitive load parsing the expression. Cognitive load can increase further
|
662
778
|
# when assignment is involved.
|
@@ -719,6 +835,11 @@ Style/TrailingCommaInHashLiteral:
|
|
719
835
|
simplifies adding, removing, and re-arranging the elements.
|
720
836
|
EnforcedStyleForMultiline: consistent_comma
|
721
837
|
|
838
|
+
# Don't combine && & || inside the same `unless` guard clause.
|
839
|
+
Style/UnlessLogicalOperators:
|
840
|
+
Enabled: true
|
841
|
+
EnforcedStyle: forbid_mixed_logical_operators
|
842
|
+
|
722
843
|
# We don't feel too strongly about percent vs bracket array style. We tend to
|
723
844
|
# use the percent style, which also happens to be Rubocop's default. So for
|
724
845
|
# pedantic consistency we'll enforce this.
|
@@ -738,3 +859,7 @@ Style/WordArray:
|
|
738
859
|
# SupportedStyles: all_comparison_operators, equality_operators_only
|
739
860
|
Style/YodaCondition:
|
740
861
|
Enabled: false
|
862
|
+
|
863
|
+
# Disabled in 1.21.0. Radius Networks has chosen to enable it.
|
864
|
+
Naming/InclusiveLanguage:
|
865
|
+
Enabled: true
|
data/common_rubocop_rails.yml
CHANGED
@@ -20,26 +20,26 @@ AllCops:
|
|
20
20
|
- 'db/migrate/**/*'
|
21
21
|
|
22
22
|
# Rails project's are not concerned with API docs normally
|
23
|
-
Documentation:
|
23
|
+
Style/Documentation:
|
24
24
|
Enabled: false
|
25
25
|
|
26
|
-
Metrics/BlockLength:
|
27
|
-
Exclude:
|
28
|
-
- 'bin/setup'
|
29
|
-
- 'bin/update'
|
30
|
-
- 'config/routes.rb'
|
31
|
-
- 'spec/rails_helper.rb'
|
32
|
-
|
33
26
|
# Rails foreign keys and indexes can get long. We want to ignore our annotation
|
34
27
|
# comments which are for these entries.
|
35
28
|
#
|
36
29
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
37
30
|
# URISchemes: http, https
|
38
|
-
|
31
|
+
Layout/LineLength:
|
39
32
|
IgnoredPatterns:
|
40
33
|
- '\A# fk_rails_'
|
41
34
|
- '\A# index_'
|
42
35
|
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Exclude:
|
38
|
+
- 'bin/setup'
|
39
|
+
- 'bin/update'
|
40
|
+
- 'config/routes.rb'
|
41
|
+
- 'spec/rails_helper.rb'
|
42
|
+
|
43
43
|
# For our Rails apps several of them use the `respond_to` with `format` blocks
|
44
44
|
# to handle various mime types (mostly HTML and JSON). Given our `do` / `end`
|
45
45
|
# block style for non-functional blocks (which includes both `respond_to` and
|
@@ -106,19 +106,39 @@ Rails/ApplicationRecord:
|
|
106
106
|
Rails/CreateTableWithTimestamps:
|
107
107
|
Enabled: false
|
108
108
|
|
109
|
+
# This cop looks for uses of default_scope because named scopes are preferred:
|
110
|
+
# https://rails.rubystyle.guide/#named-scopes
|
111
|
+
Rails/DefaultScope:
|
112
|
+
Enabled: true
|
113
|
+
|
114
|
+
# We were originally going to disable this, but after much discussion agreed that enabling
|
115
|
+
# this cop with AllowReads: true should be relatively painless.
|
116
|
+
Rails/EnvironmentVariableAccess:
|
117
|
+
Enabled: true
|
118
|
+
AllowReads: true
|
119
|
+
|
109
120
|
# Usage of `find_by` is more expressive of intent than `where.first`. We should
|
110
121
|
# check all app code, not just the models to improve intent expression.
|
111
122
|
#
|
112
123
|
# Since rake tasks often live in `lib` we also check all of lib as well.
|
113
124
|
#
|
125
|
+
# We are also disabling the default IgnoreWhereFirst that was added in version
|
126
|
+
# 2.11
|
127
|
+
#
|
114
128
|
# Configuration parameters: Include.
|
115
129
|
# Include: app/models/**/*.rb
|
116
130
|
Rails/FindBy:
|
117
131
|
Enabled: true
|
132
|
+
IgnoreWhereFirst: false
|
118
133
|
Include:
|
119
134
|
- 'app/**/*.rb'
|
120
135
|
- 'lib/**/*.rb'
|
121
136
|
|
137
|
+
# This cop enforces that ActiveRecord#find is used instead of where.take!, find_by!, and find_by_id!
|
138
|
+
# to retrieve a single record by primary key when you expect it to be found.
|
139
|
+
Rails/FindById:
|
140
|
+
Enabled: true
|
141
|
+
|
122
142
|
# Usage of `each` for large datasets can be a performance issue; specially a
|
123
143
|
# drain on system memory. When possible it's better to use `find_each` so that
|
124
144
|
# chunks of data are evaluated at a time.
|
@@ -150,6 +170,45 @@ Rails/HasAndBelongsToMany:
|
|
150
170
|
Rails/IgnoredSkipActionFilterOption:
|
151
171
|
Enabled: false
|
152
172
|
|
173
|
+
# We do not care about this check due to its lack of configuration.
|
174
|
+
#
|
175
|
+
# Some of the team finds the naming of this method is more confusing than using
|
176
|
+
# `each_with_object`. We all agree the other examples are bad and should not be
|
177
|
+
# used:
|
178
|
+
#
|
179
|
+
# # OK for us
|
180
|
+
# [1, 2, 3].each_with_object({}) { |el, h| h[foo(el)] = el }
|
181
|
+
#
|
182
|
+
# # Bad
|
183
|
+
# [1, 2, 3].to_h { |el| [foo(el), el] }
|
184
|
+
# [1, 2, 3].map { |el| [foo(el), el] }.to_h
|
185
|
+
# Hash[[1, 2, 3].collect { |el| [foo(el), el] }]
|
186
|
+
#
|
187
|
+
# If this check supports configuration in the future so that we can allow
|
188
|
+
# `each_with_object` then we'll turn it back on.
|
189
|
+
Rails/IndexBy:
|
190
|
+
Enabled: false
|
191
|
+
|
192
|
+
# We find the name of this method to be very confusing. We'd prefer this method
|
193
|
+
# is never used.
|
194
|
+
Rails/IndexWith:
|
195
|
+
Enabled: false
|
196
|
+
|
197
|
+
# This cop enforces the use of ids over pluck(:id) and pluck(primary_key).
|
198
|
+
# https://rails.rubystyle.guide/#ids
|
199
|
+
Rails/PluckId:
|
200
|
+
Enabled: true
|
201
|
+
|
202
|
+
# This cop identifies places where pluck is used in where query methods and can be replaced with
|
203
|
+
# select. Since pluck is an eager method and hits the database immediately, using select helps to
|
204
|
+
# avoid additional database queries.
|
205
|
+
#
|
206
|
+
# When the EnforcedStyle is aggressive then all calls to pluck in the where is used as offenses.
|
207
|
+
# This may lead to false positives as the cop cannot replace to select between calls to pluck on an
|
208
|
+
# ActiveRecord::Relation instance vs a call to pluck on an Array instance.
|
209
|
+
Rails/PluckInWhere:
|
210
|
+
EnforcedStyle: aggressive
|
211
|
+
|
153
212
|
# The ActiveSupport monkey patches for `present?` are nearly all defined as:
|
154
213
|
#
|
155
214
|
# !blank?
|
@@ -179,6 +238,10 @@ Rails/Present:
|
|
179
238
|
Rails/ReadWriteAttribute:
|
180
239
|
Enabled: false
|
181
240
|
|
241
|
+
# Enabling this because it is disabled by default and we want it.
|
242
|
+
Rails/ReversibleMigrationMethodDefinition:
|
243
|
+
Enabled: true
|
244
|
+
|
182
245
|
# This ensures we do not ignore potential validation issues in the code. Doing
|
183
246
|
# so can lead to strange and surprising bugs where records are expected to
|
184
247
|
# be created, or be modified, but are not.
|
@@ -210,6 +273,13 @@ Rails/ReadWriteAttribute:
|
|
210
273
|
Rails/SaveBang:
|
211
274
|
Enabled: true
|
212
275
|
|
276
|
+
# This cop enforces that short forms of I18n methods are used: t instead of translate and l instead
|
277
|
+
# of localize. We want this because it's a pain to use the full method names over and over in view
|
278
|
+
# code. When the EnforcedStyle is aggressive then all translate and localize calls without a
|
279
|
+
# receiver are added as offenses.
|
280
|
+
Rails/ShortI18n:
|
281
|
+
EnforcedStyle: aggressive
|
282
|
+
|
213
283
|
# According to the Rails docs while the following methods skip validations they
|
214
284
|
# only update the specified (single) attribute reducing risks. We'd rather not
|
215
285
|
# warn for those cases:
|
@@ -227,14 +297,19 @@ Rails/SaveBang:
|
|
227
297
|
# - http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html
|
228
298
|
# - http://api.rubyonrails.org/classes/ActiveRecord/Relation.html
|
229
299
|
#
|
230
|
-
# Configuration parameters:
|
231
|
-
#
|
300
|
+
# Configuration parameters: ForbiddenMethods, AllowedMethods.
|
301
|
+
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, toggle!, touch, update_all, update_attribute, update_column, update_columns, update_counters
|
232
302
|
Rails/SkipsModelValidations:
|
233
|
-
|
303
|
+
AllowedMethods:
|
234
304
|
- 'decrement!'
|
235
305
|
- 'increment!'
|
236
306
|
- 'touch'
|
237
307
|
|
308
|
+
# We don't want to be forced to use squish in SQL or JSON heredocs (especially
|
309
|
+
# in specs).
|
310
|
+
Rails/SquishedSQLHeredocs:
|
311
|
+
Enabled: false
|
312
|
+
|
238
313
|
# Rails uses compact style by default so we're disabling this with a :hammer:
|
239
314
|
# for things likely to be generated by Rails (i.e. most things in app).
|
240
315
|
#
|
@@ -109,7 +109,14 @@ module Radius
|
|
109
109
|
# factory {Radius::Spec::ModelFactory.catalog}.
|
110
110
|
class TemplateNotFound < KeyError; end
|
111
111
|
|
112
|
-
class << self
|
112
|
+
class << self # rubocop:disable Style/ClassMethodsDefinitions
|
113
|
+
# Style Note: We are using this class method style because we need to
|
114
|
+
# call `alias_method` within this module's singleton class context.
|
115
|
+
# Ruby did not introduce access to `singleton_class` until 2.7. Once we
|
116
|
+
# drop support for Ruby < 2.7 we can switch styles and use:
|
117
|
+
#
|
118
|
+
# singleton_class.alias_method :factory, :define_factory
|
119
|
+
|
113
120
|
# Suggested method for defining multiple factory templates at once.
|
114
121
|
#
|
115
122
|
# Most projects end up having many domain models which need factories
|
@@ -482,10 +489,8 @@ module Radius
|
|
482
489
|
end
|
483
490
|
|
484
491
|
# Try to load the factories defined for the specs
|
485
|
-
# rubocop:disable Lint/HandleExceptions
|
486
492
|
begin
|
487
493
|
require 'support/model_factories'
|
488
494
|
rescue LoadError
|
489
495
|
# Ignore as this is an optional convenience feature
|
490
496
|
end
|
491
|
-
# rubocop:enable Lint/HandleExceptions
|
data/lib/radius/spec/rspec.rb
CHANGED
@@ -22,6 +22,10 @@ RSpec.configure do |config|
|
|
22
22
|
# ...rather than:
|
23
23
|
# # => "be bigger than 2"
|
24
24
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
25
|
+
|
26
|
+
# The default is to warn, but this normally just gets ignored by
|
27
|
+
# developers. It's best to fix the problem then live with the warning.
|
28
|
+
expectations.on_potential_false_positives = :raise
|
25
29
|
end
|
26
30
|
|
27
31
|
# rspec-mocks config goes here. You can use an alternate test double
|
@@ -101,6 +105,11 @@ RSpec.configure do |config|
|
|
101
105
|
# as the one that triggered the failure.
|
102
106
|
Kernel.srand config.seed
|
103
107
|
|
108
|
+
# Common shared_example / shared_context inclusion alias for behavior driven
|
109
|
+
# development
|
110
|
+
config.alias_it_should_behave_like_to :has_behavior
|
111
|
+
config.alias_it_should_behave_like_to :it_has_behavior, 'has behavior:'
|
112
|
+
|
104
113
|
config.when_first_matching_example_defined(
|
105
114
|
:model_factory,
|
106
115
|
:model_factories,
|
@@ -124,6 +133,11 @@ RSpec.configure do |config|
|
|
124
133
|
config.include Radius::Spec::ModelFactory, type: :feature
|
125
134
|
end
|
126
135
|
|
136
|
+
config.when_first_matching_example_defined(type: :helper) do
|
137
|
+
require 'radius/spec/model_factory'
|
138
|
+
config.include Radius::Spec::ModelFactory, type: :helper
|
139
|
+
end
|
140
|
+
|
127
141
|
config.when_first_matching_example_defined(type: :job) do
|
128
142
|
require 'radius/spec/model_factory'
|
129
143
|
config.include Radius::Spec::ModelFactory, type: :job
|
data/lib/radius/spec/vcr.rb
CHANGED
@@ -10,15 +10,15 @@ VCR.configure do |config|
|
|
10
10
|
config.ignore_localhost = true
|
11
11
|
|
12
12
|
record_mode = case
|
13
|
+
when ENV['CI']
|
14
|
+
# Never let CI record
|
15
|
+
:none
|
13
16
|
when RSpec.configuration.files_to_run.one?
|
14
17
|
# When developing new features we often run new specs in
|
15
18
|
# isolation as we write the code. This is the time to allow
|
16
19
|
# creating the cassettes.
|
17
20
|
:once
|
18
|
-
|
19
|
-
# Never let CI record
|
20
|
-
:none
|
21
|
-
else
|
21
|
+
else # rubocop:disable Lint/DuplicateBranch
|
22
22
|
# Default to blocking new requests to catch issues
|
23
23
|
:none
|
24
24
|
end
|
@@ -91,10 +91,8 @@ RSpec.configure do |config|
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# Try to any custom VCR config for the app
|
94
|
-
# rubocop:disable Lint/HandleExceptions
|
95
94
|
begin
|
96
95
|
require 'support/vcr'
|
97
96
|
rescue LoadError
|
98
97
|
# Ignore as this is an optional convenience feature
|
99
98
|
end
|
100
|
-
# rubocop:enable Lint/HandleExceptions
|