rubocop-config-captive 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b792b47ba1dab2270b0e7509cf6533a85cd27e4d9ecb865de1659f27176c86ce
4
- data.tar.gz: 2ad3adee19ed6fe6d4ef07b0b4c7e68e349a732fe22ec1d4cc1baabcd74a6841
3
+ metadata.gz: 0c8513544ecc3a95a4dd8315e0b9096386168107c8acf6dd03705748ff69eb69
4
+ data.tar.gz: 80beab80c12d93db9d69652be8dd48a0c631beb87abbcd11f4d5fcf8526c76d4
5
5
  SHA512:
6
- metadata.gz: 3f890d61085363edcb57cdf460127f07f5f3b31b29cd560dd14728d026faddf596495bb0d4654659071289278beac58dfc84a325b11cbdb519550bbf364e87a8
7
- data.tar.gz: f96ed6a1a39f61a0c131220631d4c7e33503d8791cf00985ecac62a483478316b952770838b13921cd7ffde299a4fa5c69634c8dbf65df3c18b7745a287ee3cd
6
+ metadata.gz: 6e1fdab22010877255fa49451feee1502974f520c6e9d450b3d5e087c86fb53339e553a6a2bb2c07600fe18e127f7a31cfd2f862b340db0c54a9afd9fd757a06
7
+ data.tar.gz: 573648923949ed27dfc0fa32b979ef66ccbc218bf9353724616ddd584a1d5e10b270e67c616befbb192f8d70428f28260a7d18a5606be49c25fc49430fcaee51
data/Gemfile CHANGED
@@ -4,6 +4,10 @@ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
+ group :development, :test do
8
+ gem "rake", "13.4.2"
9
+ end
10
+
7
11
  group :development do
8
12
  gem "yard", "~> 0.9.34"
9
13
  end
@@ -137,7 +137,7 @@ Lint/MissingCopEnableDirective:
137
137
  # a = 1
138
138
  # # rubocop:enable SomeCop
139
139
  # .inf for any size
140
- MaximumRangeSize: .inf
140
+ MaxRangeSize: .inf
141
141
  Description: 'Checks for a `# rubocop:enable` after `# rubocop:disable`'
142
142
  Enabled: true
143
143
 
@@ -4,6 +4,7 @@ require:
4
4
  - ../lib/rubocop/cop/captive/translation/rails_i18n_presence.rb
5
5
  - ../lib/rubocop/cop/captive/translation/kaminari_i18n_presence.rb
6
6
  - ../lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
7
+ - ../lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
7
8
  - ../lib/rubocop/cop/captive/rails/after_commit_not_allowed.rb
8
9
  - ../lib/rubocop/cop/captive/rails/force_ssl_enabled_in_production.rb
9
10
  - ../lib/rubocop/cop/captive/rails/migration_methods.rb
@@ -43,6 +44,21 @@ Captive/RSpec/SpecifyBeforeParameter:
43
44
  Include:
44
45
  - 'spec/**/*'
45
46
 
47
+ Captive/RSpec/NoDbInUnitSpecs:
48
+ Description: 'Do not hit the database in unit tests. Use `instance_double` or `Model.new` instead. If testing a scope, move to spec/integration.'
49
+ Enabled: true
50
+ Include:
51
+ - 'spec/**/*'
52
+ AllowedPaths:
53
+ - 'spec/requests'
54
+ - 'spec/system'
55
+ - 'spec/features'
56
+ - 'spec/integration'
57
+ - 'spec/factories'
58
+ - 'spec/services'
59
+ - 'spec/jobs'
60
+ - 'spec/support'
61
+
46
62
  # Rails
47
63
  Captive/Rails/AfterCommitNotAllowed:
48
64
  Description: "Interdit l'utilisation de `after_commit` dans les modèles Rails."
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Captive
5
- VERSION = "2.2.1"
5
+ VERSION = "2.3.1"
6
6
  end
7
7
  end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Captive
6
+ module RSpec
7
+ # Do not create database records in unit tests.
8
+ # Use `build`, `instance_double`, or stubs instead.
9
+ class NoDbInUnitSpecs < Base
10
+ MSG =
11
+ "Do not hit the database in unit tests. " \
12
+ "Use `instance_double` or `Model.new` instead. " \
13
+ "If testing a scope, move to spec/integration."
14
+
15
+ DEFAULT_ALLOWED_PATHS = %w[
16
+ spec/requests spec/system spec/features spec/integration
17
+ spec/factories spec/services spec/jobs spec/support
18
+ ].freeze
19
+
20
+ def_node_matcher :factory_bot_db?, <<~PATTERN
21
+ (send (const nil? :FactoryBot) {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
22
+ PATTERN
23
+
24
+ def_node_matcher :standalone_factory_bot_db?, <<~PATTERN
25
+ (send nil? {:create :create_list :create_pair :build :build_list :build_pair :build_stubbed :build_stubbed_list} ...)
26
+ PATTERN
27
+
28
+ def_node_matcher :ar_create?, <<~PATTERN
29
+ (send (const nil? _) {:create :create!} ...)
30
+ PATTERN
31
+
32
+ def_node_matcher :ar_save?, <<~PATTERN
33
+ (send _ {:save :save!} ...)
34
+ PATTERN
35
+
36
+ def on_send(node)
37
+ return unless unit_spec?
38
+ return unless db_creation?(node)
39
+
40
+ add_offense(node)
41
+ end
42
+
43
+ private
44
+
45
+ def unit_spec?
46
+ path = processed_source.path
47
+ return false unless path&.include?("spec/")
48
+
49
+ allowed_paths.none? { |allowed| path.include?(allowed) }
50
+ end
51
+
52
+ def allowed_paths
53
+ cop_config.fetch("AllowedPaths", DEFAULT_ALLOWED_PATHS)
54
+ end
55
+
56
+ def db_creation?(node)
57
+ factory_bot_db?(node) ||
58
+ standalone_factory_bot_db?(node) ||
59
+ ar_create?(node) ||
60
+ ar_save?(node)
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-config-captive
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Captive
@@ -202,6 +202,7 @@ files:
202
202
  - lib/rubocop/cop/captive/rails/no_find_by_in_scope.rb
203
203
  - lib/rubocop/cop/captive/rails/no_float_price_columns.rb
204
204
  - lib/rubocop/cop/captive/rails/no_has_many_attached.rb
205
+ - lib/rubocop/cop/captive/rspec/no_db_in_unit_specs.rb
205
206
  - lib/rubocop/cop/captive/rspec/specify_before_parameter.rb
206
207
  - lib/rubocop/cop/captive/string_where_in_scope.rb
207
208
  - lib/rubocop/cop/captive/translation/devise_i18n_presence.rb