summaryrefslogtreecommitdiff
path: root/spec/rubocop
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 15:44:42 +0000
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/rubocop
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
downloadgitlab-ce-4555e1b21c365ed8303ffb7a3325d773c9b8bf31.tar.gz
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/rubocop')
-rw-r--r--spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb62
-rw-r--r--spec/rubocop/cop/inject_enterprise_edition_module_spec.rb178
-rw-r--r--spec/rubocop/cop/performance/ar_count_each_spec.rb2
-rw-r--r--spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb2
4 files changed, 105 insertions, 139 deletions
diff --git a/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb
new file mode 100644
index 00000000000..37fcdb38907
--- /dev/null
+++ b/spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb
@@ -0,0 +1,62 @@
+# frozen_string_literal: true
+
+require 'fast_spec_helper'
+require_relative '../../../rubocop/cop/active_model_errors_direct_manipulation'
+
+RSpec.describe RuboCop::Cop::ActiveModelErrorsDirectManipulation do
+ subject(:cop) { described_class.new }
+
+ context 'when modifying errors' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors[:name] << 'msg'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+
+ context 'when assigning' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors[:name] = []
+ ^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+ end
+ end
+
+ context 'when modifying errors.messages' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors.messages[:name] << 'msg'
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+
+ context 'when assigning' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors.messages[:name] = []
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+ end
+ end
+
+ context 'when modifying errors.details' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors.details[:name] << {}
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+
+ context 'when assigning' do
+ it 'registers an offense' do
+ expect_offense(<<~PATTERN)
+ user.errors.details[:name] = []
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
+ PATTERN
+ end
+ end
+ end
+end
diff --git a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
index 8bfa57031d7..962efc23453 100644
--- a/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
+++ b/spec/rubocop/cop/inject_enterprise_edition_module_spec.rb
@@ -6,173 +6,77 @@ require_relative '../../../rubocop/cop/inject_enterprise_edition_module'
RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
subject(:cop) { described_class.new }
- it 'flags the use of `prepend_if_ee EE` in the middle of a file' do
+ it 'flags the use of `prepend_mod_with` in the middle of a file' do
expect_offense(<<~SOURCE)
class Foo
- prepend_if_ee 'EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
+ prepend_mod_with('Foo')
+ ^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
end
SOURCE
end
- it 'flags the use of `prepend_if_ee QA::EE` in the middle of a file' do
+ it 'flags the use of `include_mod_with` in the middle of a file' do
expect_offense(<<~SOURCE)
class Foo
- prepend_if_ee 'QA::EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
+ include_mod_with('Foo')
+ ^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
end
SOURCE
end
-
- it 'does not flag the use of `prepend_if_ee EEFoo` in the middle of a file' do
- expect_no_offenses(<<~SOURCE)
- class Foo
- prepend_if_ee 'EEFoo'
- end
- SOURCE
- end
-
- it 'flags the use of `prepend_if_ee EE::Foo::Bar` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- prepend_if_ee 'EE::Foo::Bar'
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `prepend_if_ee(EE::Foo::Bar)` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- prepend_if_ee('EE::Foo::Bar')
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `prepend_if_ee EE::Foo::Bar::Baz` in the middle of a file' do
+ it 'flags the use of `extend_mod_with` in the middle of a file' do
expect_offense(<<~SOURCE)
class Foo
- prepend_if_ee 'EE::Foo::Bar::Baz'
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `prepend_if_ee ::EE` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- prepend_if_ee '::EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `include_if_ee EE` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- include_if_ee 'EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `include_if_ee ::EE` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- include_if_ee '::EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `extend_if_ee EE` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- extend_if_ee 'EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'flags the use of `extend_if_ee ::EE` in the middle of a file' do
- expect_offense(<<~SOURCE)
- class Foo
- extend_if_ee '::EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- end
- SOURCE
- end
-
- it 'does not flag prepending of regular modules' do
- expect_no_offenses(<<~SOURCE)
- class Foo
- prepend_if_ee 'Foo'
- end
- SOURCE
- end
-
- it 'does not flag including of regular modules' do
- expect_no_offenses(<<~SOURCE)
- class Foo
- include_if_ee 'Foo'
- end
- SOURCE
- end
-
- it 'does not flag extending using regular modules' do
- expect_no_offenses(<<~SOURCE)
- class Foo
- extend_if_ee 'Foo'
+ extend_mod_with('Foo')
+ ^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
end
SOURCE
end
- it 'does not flag the use of `prepend_if_ee EE` on the last line' do
+ it 'does not flag the use of `prepend_mod_with` on the last line' do
expect_no_offenses(<<~SOURCE)
class Foo
end
- Foo.prepend_if_ee('EE::Foo')
+ Foo.prepend_mod_with('Foo')
SOURCE
end
- it 'does not flag the use of `include_if_ee EE` on the last line' do
+ it 'does not flag the use of `include_mod_with` on the last line' do
expect_no_offenses(<<~SOURCE)
class Foo
end
- Foo.include_if_ee('EE::Foo')
+ Foo.include_mod_with('Foo')
SOURCE
end
- it 'does not flag the use of `extend_if_ee EE` on the last line' do
+ it 'does not flag the use of `extend_mod_with` on the last line' do
expect_no_offenses(<<~SOURCE)
class Foo
end
- Foo.extend_if_ee('EE::Foo')
+ Foo.extend_mod_with('Foo')
SOURCE
end
- it 'does not flag the double use of `X_if_ee` on the last line' do
+ it 'does not flag the double use of `X_mod_with` on the last line' do
expect_no_offenses(<<~SOURCE)
class Foo
end
- Foo.extend_if_ee('EE::Foo')
- Foo.include_if_ee('EE::Foo')
- Foo.prepend_if_ee('EE::Foo')
+ Foo.extend_mod_with('Foo')
+ Foo.include_mod_with('Foo')
+ Foo.prepend_mod_with('Foo')
SOURCE
end
- it 'does not flag the use of `prepend_if_ee EE` as long as all injections are at the end of the file' do
+ it 'does not flag the use of `prepend_mod_with` as long as all injections are at the end of the file' do
expect_no_offenses(<<~SOURCE)
class Foo
end
- Foo.include_if_ee('EE::Foo')
- Foo.prepend_if_ee('EE::Foo')
+ Foo.include_mod_with('Foo')
+ Foo.prepend_mod_with('Foo')
Foo.include(Bar)
# comment on prepending Bar
@@ -183,27 +87,27 @@ RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
it 'autocorrects offenses by just disabling the Cop' do
expect_offense(<<~SOURCE)
class Foo
- prepend_if_ee 'EE::Foo'
- ^^^^^^^^^^^^^^^^^^^^^^^ Injecting EE modules must be done on the last line of this file, outside of any class or module definitions
- include_if_ee 'Bar'
+ prepend_mod_with('Foo')
+ ^^^^^^^^^^^^^^^^^^^^^^^ Injecting extension modules must be done on the last line of this file, outside of any class or module definitions
+ include Bar
end
SOURCE
expect_correction(<<~SOURCE)
class Foo
- prepend_if_ee 'EE::Foo' # rubocop: disable Cop/InjectEnterpriseEditionModule
- include_if_ee 'Bar'
+ prepend_mod_with('Foo') # rubocop: disable Cop/InjectEnterpriseEditionModule
+ include Bar
end
SOURCE
end
- it 'disallows the use of prepend to inject an EE module' do
+ it 'disallows the use of prepend to inject an extension module' do
expect_offense(<<~SOURCE)
class Foo
end
Foo.prepend(EE::Foo)
- ^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
+ ^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
SOURCE
end
@@ -213,7 +117,7 @@ RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
end
Foo.prepend(QA::EE::Foo)
- ^^^^^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
+ ^^^^^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
SOURCE
end
@@ -223,7 +127,7 @@ RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
end
Foo.extend(EE::Foo)
- ^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
+ ^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
SOURCE
end
@@ -233,37 +137,37 @@ RSpec.describe RuboCop::Cop::InjectEnterpriseEditionModule do
end
Foo.include(EE::Foo)
- ^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_if_ee`, `extend_if_ee`, or `prepend_if_ee`
+ ^^^^^^^^^^^^^^^^^^^^ EE modules must be injected using `include_mod_with`, `extend_mod_with`, or `prepend_mod_with`
SOURCE
end
- it 'disallows the use of prepend_if_ee without a String' do
+ it 'disallows the use of prepend_mod_with without a String' do
expect_offense(<<~SOURCE)
class Foo
end
- Foo.prepend_if_ee(EE::Foo)
- ^^^^^^^ EE modules to inject must be specified as a String
+ Foo.prepend_mod_with(Foo)
+ ^^^ extension modules to inject must be specified as a String
SOURCE
end
- it 'disallows the use of include_if_ee without a String' do
+ it 'disallows the use of include_mod_with without a String' do
expect_offense(<<~SOURCE)
class Foo
end
- Foo.include_if_ee(EE::Foo)
- ^^^^^^^ EE modules to inject must be specified as a String
+ Foo.include_mod_with(Foo)
+ ^^^ extension modules to inject must be specified as a String
SOURCE
end
- it 'disallows the use of extend_if_ee without a String' do
+ it 'disallows the use of extend_mod_with without a String' do
expect_offense(<<~SOURCE)
class Foo
end
- Foo.extend_if_ee(EE::Foo)
- ^^^^^^^ EE modules to inject must be specified as a String
+ Foo.extend_mod_with(Foo)
+ ^^^ extension modules to inject must be specified as a String
SOURCE
end
end
diff --git a/spec/rubocop/cop/performance/ar_count_each_spec.rb b/spec/rubocop/cop/performance/ar_count_each_spec.rb
index fa7a1aba426..4aeb9e13b18 100644
--- a/spec/rubocop/cop/performance/ar_count_each_spec.rb
+++ b/spec/rubocop/cop/performance/ar_count_each_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require_relative '../../../../rubocop/cop/performance/ar_count_each.rb'
+require_relative '../../../../rubocop/cop/performance/ar_count_each'
RSpec.describe RuboCop::Cop::Performance::ARCountEach do
subject(:cop) { described_class.new }
diff --git a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
index 127c858a549..e95220756ed 100644
--- a/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
+++ b/spec/rubocop/cop/performance/ar_exists_and_present_blank_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'fast_spec_helper'
-require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank.rb'
+require_relative '../../../../rubocop/cop/performance/ar_exists_and_present_blank'
RSpec.describe RuboCop::Cop::Performance::ARExistsAndPresentBlank do
subject(:cop) { described_class.new }