Add latest changes from gitlab-org/gitlab@master
This commit is contained in:
parent
c2d10c27b4
commit
811bcc184b
|
|
@ -3,26 +3,6 @@
|
|||
InternalAffairs/ExampleHeredocDelimiter:
|
||||
Details: grace period
|
||||
Exclude:
|
||||
- 'spec/rubocop/cop/active_model_errors_direct_manipulation_spec.rb'
|
||||
- 'spec/rubocop/cop/active_record_association_reload_spec.rb'
|
||||
- 'spec/rubocop/cop/api/base_spec.rb'
|
||||
- 'spec/rubocop/cop/api/class_level_allow_access_with_scope_spec.rb'
|
||||
- 'spec/rubocop/cop/api/ensure_string_detail_spec.rb'
|
||||
- 'spec/rubocop/cop/api/grape_array_missing_coerce_spec.rb'
|
||||
- 'spec/rubocop/cop/avoid_becomes_spec.rb'
|
||||
- 'spec/rubocop/cop/avoid_route_redirect_leading_slash_spec.rb'
|
||||
- 'spec/rubocop/cop/ban_catch_throw_spec.rb'
|
||||
- 'spec/rubocop/cop/capybara/testid_finders_spec.rb'
|
||||
- 'spec/rubocop/cop/code_reuse/finder_spec.rb'
|
||||
- 'spec/rubocop/cop/code_reuse/presenter_spec.rb'
|
||||
- 'spec/rubocop/cop/code_reuse/serializer_spec.rb'
|
||||
- 'spec/rubocop/cop/code_reuse/service_class_spec.rb'
|
||||
- 'spec/rubocop/cop/code_reuse/worker_spec.rb'
|
||||
- 'spec/rubocop/cop/database/disable_referential_integrity_spec.rb'
|
||||
- 'spec/rubocop/cop/database/establish_connection_spec.rb'
|
||||
- 'spec/rubocop/cop/database/multiple_databases_spec.rb'
|
||||
- 'spec/rubocop/cop/database/rescue_query_canceled_spec.rb'
|
||||
- 'spec/rubocop/cop/database/rescue_statement_timeout_spec.rb'
|
||||
- 'spec/rubocop/cop/default_scope_spec.rb'
|
||||
- 'spec/rubocop/cop/destroy_all_spec.rb'
|
||||
- 'spec/rubocop/cop/feature_flag_usage_spec.rb'
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
---
|
||||
# Cop supports --autocorrect.
|
||||
InternalAffairs/MethodNameEndWith:
|
||||
Details: grace period
|
||||
Exclude:
|
||||
- 'rubocop/cop/gitlab/predicate_memoization.rb'
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
---
|
||||
# Cop supports --autocorrect.
|
||||
InternalAffairs/NodeFirstOrLastArgument:
|
||||
Details: grace period
|
||||
Exclude:
|
||||
- 'rubocop/cop/gitlab/const_get_inherit_false.rb'
|
||||
- 'rubocop/cop/gitlab/documentation_links/link.rb'
|
||||
- 'rubocop/cop/include_sidekiq_worker.rb'
|
||||
- 'rubocop/cop/migration/change_column_null_on_high_traffic_table.rb'
|
||||
- 'rubocop/cop/migration/versioned_migration_class.rb'
|
||||
- 'rubocop/cop/scalability/cron_worker_context.rb'
|
||||
- 'rubocop/cop/sidekiq_options_queue.rb'
|
||||
|
|
@ -69,7 +69,6 @@ RSpec/ReceiveMessages:
|
|||
- 'ee/spec/lib/google_cloud/artifact_registry/client_spec.rb'
|
||||
- 'ee/spec/lib/omni_auth/strategies/group_saml_spec.rb'
|
||||
- 'ee/spec/lib/sidebars/groups/super_sidebar_panel_spec.rb'
|
||||
- 'ee/spec/lib/sidebars/projects/super_sidebar_panel_spec.rb'
|
||||
- 'ee/spec/lib/system_check/geo/database_replication_working_check_spec.rb'
|
||||
- 'ee/spec/lib/system_check/geo/license_check_spec.rb'
|
||||
- 'ee/spec/migrations/geo/resync_direct_upload_job_artifact_registry_spec.rb'
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
156d8dc89f39affd7799101577e684229a355f1f
|
||||
4f0652cb7aee4addb41841dc6daf253b209bae7d
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ function mountBoardApp(el) {
|
|||
hasCustomFieldsFeature: parseBoolean(hasCustomFieldsFeature),
|
||||
commentTemplatePaths: JSON.parse(wiNewCommentTemplatePaths),
|
||||
statusListsAvailable: parseBoolean(el.dataset.statusListsAvailable),
|
||||
workItemStatusAvailable: parseBoolean(el.dataset.workItemStatusAvailable),
|
||||
hasStatusFeature: parseBoolean(el.dataset.workItemStatusAvailable),
|
||||
},
|
||||
render: (createComponent) => createComponent(BoardApp),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1072,8 +1072,9 @@ The following fields are populated by default:
|
|||
| Field | Value |
|
||||
|-------------------------------------------------------------------|-------|
|
||||
| `_type` | `https://in-toto.io/Statement/v0.1` |
|
||||
| `subject.name` | The filename of the artifact. |
|
||||
| `subject.digest.sha256` | The artifact's `sha256` checksum. |
|
||||
| `subject` | Set of software artifacts the metadata applies to |
|
||||
| `subject[].name` | The filename of the artifact. |
|
||||
| `subject[].sha256` | The artifact's `sha256` checksum. |
|
||||
| `predicateType` | `https://slsa.dev/provenance/v1` |
|
||||
| `predicate.buildDefinition.buildType` | `https://gitlab.com/gitlab-org/gitlab-runner/-/blob/{GITLAB_RUNNER_VERSION}/PROVENANCE.md`. For example, v15.0.0 |
|
||||
| `predicate.runDetails.builder.id` | A URI pointing to the runner details page, for example, `https://gitlab.com/gitlab-com/www-gitlab-com/-/runners/3785264`. |
|
||||
|
|
@ -1090,6 +1091,76 @@ The following fields are populated by default:
|
|||
| `predicate.runDetails.metadata.startedOn` | The time when the build was started. This field is `RFC3339` formatted. |
|
||||
| `predicate.runDetails.metadata.finishedOn` | The time when the build ended. Because metadata generation happens during the build, this time is slightly earlier than the one reported in GitLab. This field is `RFC3339` formatted. |
|
||||
|
||||
### Example provenance statement
|
||||
|
||||
The following code contains an example provenance statement:
|
||||
|
||||
```json
|
||||
{
|
||||
"_type": "https://in-toto.io/Statement/v0.1",
|
||||
"predicateType": "https://slsa.dev/provenance/v1",
|
||||
"subject": [
|
||||
{
|
||||
"name": "x.txt",
|
||||
"digest": {
|
||||
"sha256": "ac097997b6ec7de591d4f11315e4aa112e515bb5d3c52160d0c571298196ea8b"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "y.txt",
|
||||
"digest": {
|
||||
"sha256": "9eb634f80da849d828fcf42740d823568c49e8d7b532886134f9086246b1fdf3"
|
||||
}
|
||||
}
|
||||
],
|
||||
"predicate": {
|
||||
"buildDefinition": {
|
||||
"buildType": "https://gitlab.com/gitlab-org/gitlab-runner/-/blob/2147fb44/PROVENANCE.md",
|
||||
"externalParameters": {
|
||||
"CI": "",
|
||||
"CI_API_GRAPHQL_URL": "",
|
||||
"CI_API_V4_URL": "",
|
||||
"CI_COMMIT_AUTHOR": "",
|
||||
"CI_COMMIT_BEFORE_SHA": "",
|
||||
"CI_COMMIT_BRANCH": "",
|
||||
"CI_COMMIT_DESCRIPTION": "",
|
||||
"CI_COMMIT_MESSAGE": "",
|
||||
[... additional environmental variables ...]
|
||||
"entryPoint": "build-job",
|
||||
"source": "https://gitlab.com/gitlab-org/secure/tests/fcatteau/test-runner-generated-slsa-statement"
|
||||
},
|
||||
"internalParameters": {
|
||||
"architecture": "amd64",
|
||||
"executor": "docker+machine",
|
||||
"job": "10340684631",
|
||||
"name": "green-4.saas-linux-small-amd64.runners-manager.gitlab.com/default"
|
||||
},
|
||||
"resolvedDependencies": [
|
||||
{
|
||||
"uri": "https://gitlab.com/gitlab-org/secure/tests/fcatteau/test-runner-generated-slsa-statement",
|
||||
"digest": {
|
||||
"sha256": "bdd2ecda9ef57b129c88617a0215afc9fb223521"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"runDetails": {
|
||||
"builder": {
|
||||
"id": "https://gitlab.com/gitlab-org/secure/tests/fcatteau/test-runner-generated-slsa-statement/-/runners/12270857",
|
||||
"version": {
|
||||
"gitlab-runner": "2147fb44"
|
||||
}
|
||||
},
|
||||
"metadata": {
|
||||
"invocationID": "10340684631",
|
||||
"startedOn": "2025-06-13T07:25:13Z",
|
||||
"finishedOn": "2025-06-13T07:25:40Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Staging directory
|
||||
|
||||
{{< history >}}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
ARG GDK_SHA=1e8d0e487d1e834a441986ce663a9d5c7c2078fc
|
||||
ARG GDK_SHA=75d073fbd5e137ecbfe5832c491b4a9a258deefe
|
||||
# Use tag prefix when running on 'stable' branch to make sure 'protected' image is used which is not deleted by registry cleanup
|
||||
ARG GDK_BASE_TAG_PREFIX
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ module RuboCop
|
|||
if arg = second_argument(node)
|
||||
corrector.replace(arg.source_range, 'false')
|
||||
else
|
||||
first_argument = node.arguments[0]
|
||||
first_argument = node.first_argument
|
||||
corrector.insert_after(first_argument.source_range, ', false')
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ module RuboCop
|
|||
return
|
||||
end
|
||||
|
||||
node.arguments.first.value
|
||||
node.first_argument.value
|
||||
end
|
||||
|
||||
def check_md_extension(node, path)
|
||||
|
|
@ -108,7 +108,7 @@ module RuboCop
|
|||
path_without_extension = path_without_anchor.gsub(/#{extension_pattern}$/, '')
|
||||
arg_with_md_extension = path.gsub(/#{path_without_extension}#{extension_pattern}(\#.+)?$/,
|
||||
"#{path_without_extension}.md\\2")
|
||||
corrector.replace(node.arguments.first.source_range, "'#{arg_with_md_extension}'")
|
||||
corrector.replace(node.first_argument.source_range, "'#{arg_with_md_extension}'")
|
||||
end
|
||||
path_without_anchor += ".md"
|
||||
end
|
||||
|
|
@ -118,7 +118,7 @@ module RuboCop
|
|||
|
||||
def check_file_exists(node, docs_file_path)
|
||||
unless docs_file_exists?(docs_file_path)
|
||||
add_offense(node.arguments.first.loc.expression,
|
||||
add_offense(node.first_argument.loc.expression,
|
||||
message: format(MSG_FILE_NOT_FOUND, file_path: docs_file_path))
|
||||
return false
|
||||
end
|
||||
|
|
@ -128,7 +128,7 @@ module RuboCop
|
|||
|
||||
def check_anchor_type(node, anchor)
|
||||
unless anchor.instance_of? String
|
||||
loc = anchor_param(node)&.loc&.expression || node.arguments.first.loc.expression
|
||||
loc = anchor_param(node)&.loc&.expression || node.first_argument.loc.expression
|
||||
add_offense(loc, message: MSG_ANCHOR_NOT_A_STRING)
|
||||
return false
|
||||
end
|
||||
|
|
@ -139,7 +139,7 @@ module RuboCop
|
|||
def check_anchor_exists(node, anchor, docs_file_path)
|
||||
return true if anchor_exists_in_markdown?(anchor, docs_file_path)
|
||||
|
||||
loc = anchor_param(node)&.loc&.expression || node.arguments.first.loc.expression
|
||||
loc = anchor_param(node)&.loc&.expression || node.first_argument.loc.expression
|
||||
|
||||
add_offense(loc, message: format(MSG_ANCHOR_NOT_FOUND, anchor: anchor, file_path: docs_file_path))
|
||||
|
||||
|
|
@ -151,7 +151,7 @@ module RuboCop
|
|||
end
|
||||
|
||||
def first_argument_is_string?(node)
|
||||
return true if node.arguments.first.str_type?
|
||||
return true if node.first_argument.str_type?
|
||||
|
||||
false
|
||||
end
|
||||
|
|
@ -179,13 +179,13 @@ module RuboCop
|
|||
end
|
||||
|
||||
def has_anchor?(node)
|
||||
return !node.arguments.first.value[/#(.+)$/, 1].nil? if node.arguments.length == 1
|
||||
return !node.first_argument.value[/#(.+)$/, 1].nil? if node.arguments.length == 1
|
||||
|
||||
anchor_param(node) != nil
|
||||
end
|
||||
|
||||
def get_anchor(node)
|
||||
return node.arguments.first.value[/#(.+)$/, 1] if node.arguments.length == 1
|
||||
return node.first_argument.value[/#(.+)$/, 1] if node.arguments.length == 1
|
||||
|
||||
anchor_node = anchor_param(node)
|
||||
return unless anchor_node
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ module RuboCop
|
|||
private
|
||||
|
||||
def predicate_method?(node)
|
||||
node.method_name.to_s.end_with?('?')
|
||||
node.predicate_method?
|
||||
end
|
||||
|
||||
def or_ivar_assignment?(or_assignment)
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ module RuboCop
|
|||
def on_send(node)
|
||||
return unless includes_sidekiq_worker?(node)
|
||||
|
||||
add_offense(node.arguments.first) do |corrector|
|
||||
corrector.replace(node.arguments.first, 'ApplicationWorker')
|
||||
add_offense(node.first_argument) do |corrector|
|
||||
corrector.replace(node.first_argument, 'ApplicationWorker')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ module RuboCop
|
|||
private
|
||||
|
||||
def violates?(node)
|
||||
table_name = node.arguments.first.try(:value)
|
||||
table_name = node.first_argument.try(:value)
|
||||
|
||||
return unless table_name
|
||||
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ module RuboCop
|
|||
def old_version_migration_class?(class_node)
|
||||
parent_class_node = class_node.parent_class
|
||||
return false if parent_class_node.nil?
|
||||
return false unless parent_class_node.send_type? && parent_class_node.arguments.last.float_type?
|
||||
return false unless parent_class_node.send_type? && parent_class_node.last_argument.float_type?
|
||||
return false unless parent_class_node.children[0].const_name == GITLAB_MIGRATION_CLASS
|
||||
|
||||
parent_class_node.arguments[0].value < CURRENT_MIGRATION_VERSION
|
||||
parent_class_node.first_argument.value < CURRENT_MIGRATION_VERSION
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ module RuboCop
|
|||
return if defines_contexts?(node.parent)
|
||||
return if schedules_with_batch_context?(node.parent)
|
||||
|
||||
add_offense(node.arguments.first)
|
||||
add_offense(node.first_argument)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ module RuboCop
|
|||
def on_send(node)
|
||||
return unless sidekiq_options?(node)
|
||||
|
||||
node.arguments.first.each_node(:pair) do |pair|
|
||||
node.first_argument.each_node(:pair) do |pair|
|
||||
key_name = pair.key.children[0]
|
||||
|
||||
add_offense(pair) if key_name == :queue
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ describe('BoardTopBar', () => {
|
|||
healthStatusFeatureAvailable: false,
|
||||
hasCustomFieldsFeature: false,
|
||||
statusListsAvailable: false,
|
||||
workItemStatusAvailable: false,
|
||||
hasStatusFeature: false,
|
||||
...provide,
|
||||
},
|
||||
stubs: { IssueBoardFilteredSearch },
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ RSpec.describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', ty
|
|||
|
||||
it 'application_settings/accounts_and_limit.html' do
|
||||
stub_application_setting(user_default_external: false)
|
||||
stub_licensed_features(personal_access_token_expiration_policy: true)
|
||||
|
||||
get :general
|
||||
|
||||
|
|
|
|||
|
|
@ -6,54 +6,54 @@ require_relative '../../../rubocop/cop/active_model_errors_direct_manipulation'
|
|||
RSpec.describe RuboCop::Cop::ActiveModelErrorsDirectManipulation do
|
||||
context 'when modifying errors' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors[:name] << 'msg'
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
context 'when assigning' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors[:name] = []
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when modifying errors.messages' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors.messages[:name] << 'msg'
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
context 'when assigning' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors.messages[:name] = []
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when modifying errors.details' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors.details[:name] << {}
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
context 'when assigning' do
|
||||
it 'registers an offense' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user.errors.details[:name] = []
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid manipulating errors hash directly. [...]
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,50 +6,50 @@ require_relative '../../../rubocop/cop/active_record_association_reload'
|
|||
RSpec.describe RuboCop::Cop::ActiveRecordAssociationReload do
|
||||
context 'when using ActiveRecord::Base' do
|
||||
it 'registers an offense on reload usage' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
users = User.all
|
||||
users.reload
|
||||
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not register an offense on reset usage' do
|
||||
expect_no_offenses(<<~PATTERN)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
users = User.all
|
||||
users.reset
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using ActiveRecord::Relation' do
|
||||
it 'registers an offense on reload usage' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
user = User.new
|
||||
user.reload
|
||||
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not register an offense on reset usage' do
|
||||
expect_no_offenses(<<~PATTERN)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
user = User.new
|
||||
user.reset
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context 'when using on self' do
|
||||
it 'registers an offense on reload usage' do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
reload
|
||||
^^^^^^ Use reset instead of reload. For more details check the https://gitlab.com/gitlab-org/gitlab-foss/issues/60218.
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not register an offense on reset usage' do
|
||||
expect_no_offenses(<<~PATTERN)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
reset
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ RSpec.describe RuboCop::Cop::API::Base do
|
|||
|
||||
%w[Grape::API ::Grape::API Grape::API::Instance ::Grape::API::Instance].each do |offense|
|
||||
it "adds an offense when inheriting from #{offense}" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class SomeAPI < #{offense}
|
||||
#{'^' * offense.length} #{described_class::MSG}
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
|
||||
expect_correction(corrected)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -8,20 +8,20 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
|
||||
context "when there is no `allow_access_with_scope`" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
namespace 'my_namespace' do
|
||||
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is class level `allow_access_with_scope`" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
allow_access_with_scope :my_scope
|
||||
|
|
@ -29,13 +29,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is `allow_access_with_scope` under namespace" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
namespace 'my_namespace' do
|
||||
|
|
@ -43,13 +43,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is `allow_access_with_scope` under group" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
group 'my_namespace' do
|
||||
|
|
@ -57,13 +57,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is `allow_access_with_scope` under resource" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
resource 'my_namespace' do
|
||||
|
|
@ -71,13 +71,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is `allow_access_with_scope` under resources" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
resources 'my_namespace' do
|
||||
|
|
@ -85,13 +85,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there is `allow_access_with_scope` under segment" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
segment 'my_namespace' do
|
||||
|
|
@ -99,13 +99,13 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are `allow_access_with_scope`s both class level and under namespace" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class MyClass < ::API::Base
|
||||
include APIGuard
|
||||
allow_access_with_scope :my_scope
|
||||
|
|
@ -114,7 +114,7 @@ RSpec.describe RuboCop::Cop::API::ClassLevelAllowAccessWithScope, feature_catego
|
|||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
|
||||
context "when detail field uses a string" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -19,7 +19,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
it "does not add an offense" do
|
||||
baz = "bat"
|
||||
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -35,13 +35,13 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when detail field uses a multiline string" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -50,7 +50,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
it "does not add an offense" do
|
||||
pending
|
||||
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
DESCRIPTION = 'A string'
|
||||
|
|
@ -68,13 +68,13 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when detail field uses a HEREDOC string" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -85,13 +85,13 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when detail field uses an array" do
|
||||
it "adds an offense" do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -101,17 +101,17 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
||||
context "when detail field is outside of desc block" do
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo
|
||||
detail ["foo", "bar"]
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -122,7 +122,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
|
||||
it "does not add an offense" do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI
|
||||
resource :projects do
|
||||
desc 'Some API thing related to a project' do
|
||||
|
|
@ -130,7 +130,7 @@ RSpec.describe RuboCop::Cop::API::EnsureStringDetail do
|
|||
end
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -11,29 +11,29 @@ RSpec.describe RuboCop::Cop::API::GrapeArrayMissingCoerce do
|
|||
end
|
||||
|
||||
it 'adds an offense with a required parameter' do
|
||||
expect_offense(<<~TYPE)
|
||||
expect_offense(<<~RUBY)
|
||||
class SomeAPI < Grape::API::Instance
|
||||
params do
|
||||
requires :values, type: Array[String]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
TYPE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'adds an offense with an optional parameter' do
|
||||
expect_offense(<<~TYPE)
|
||||
expect_offense(<<~RUBY)
|
||||
class SomeAPI < Grape::API::Instance
|
||||
params do
|
||||
optional :values, type: Array[String]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #{msg}
|
||||
end
|
||||
end
|
||||
TYPE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not add an offense' do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeAPI < Grape::API::Instance
|
||||
params do
|
||||
requires :values, type: Array[String], coerce_with: ->(val) { val.split(',').map(&:strip) }
|
||||
|
|
@ -42,16 +42,16 @@ RSpec.describe RuboCop::Cop::API::GrapeArrayMissingCoerce do
|
|||
desc: 'Return issues which are assigned to the user with the given ID'
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not add an offense for unrelated classes' do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class SomeClass
|
||||
params do
|
||||
requires :values, type: Array[String]
|
||||
end
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,25 +5,25 @@ require_relative '../../../rubocop/cop/avoid_becomes'
|
|||
|
||||
RSpec.describe RuboCop::Cop::AvoidBecomes do
|
||||
it 'flags the use of becomes with a constant parameter' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
foo.becomes(Project)
|
||||
^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of becomes with a namespaced constant parameter' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
foo.becomes(Namespace::Group)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of becomes with a dynamic parameter' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
model = Namespace
|
||||
project = Project.first
|
||||
project.becomes(model)
|
||||
^^^^^^^^^^^^^^^^^^^^^^ Avoid the use of becomes(SomeConstant), [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,19 +9,19 @@ RSpec.describe RuboCop::Cop::AvoidRouteRedirectLeadingSlash do
|
|||
end
|
||||
|
||||
it 'registers an offense when redirect has a leading slash and corrects', :aggregate_failures do
|
||||
expect_offense(<<~PATTERN)
|
||||
expect_offense(<<~RUBY)
|
||||
root to: redirect("/-/route")
|
||||
^^^^^^^^^^^^^^^^^^^^ Do not use a leading "/" in route redirects
|
||||
PATTERN
|
||||
RUBY
|
||||
|
||||
expect_correction(<<~PATTERN)
|
||||
expect_correction(<<~RUBY)
|
||||
root to: redirect("-/route")
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not register an offense when redirect does not have a leading slash' do
|
||||
expect_no_offenses(<<~PATTERN)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
root to: redirect("-/route")
|
||||
PATTERN
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,20 +6,20 @@ require_relative '../../../rubocop/cop/ban_catch_throw'
|
|||
|
||||
RSpec.describe RuboCop::Cop::BanCatchThrow do
|
||||
it 'registers an offense when `catch` or `throw` are used' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
catch(:foo) {
|
||||
^^^^^^^^^^^ Do not use catch or throw unless a gem's API demands it.
|
||||
throw(:foo)
|
||||
^^^^^^^^^^^ Do not use catch or throw unless a gem's API demands it.
|
||||
}
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not register an offense for a method called catch or throw' do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
foo.catch(:foo) {
|
||||
foo.throw(:foo)
|
||||
}
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ RSpec.describe RuboCop::Cop::Capybara::TestidFinders, feature_category: :shared
|
|||
|
||||
with_them do
|
||||
it 'does not register an offense' do
|
||||
expect_offense(<<~CODE, node: code)
|
||||
expect_offense(<<~RUBY, node: code)
|
||||
%{node}
|
||||
^{node} Prefer to use custom helper method[...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Finder do
|
|||
.to receive(:in_finder?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
BarFinder.new.execute
|
||||
^^^^^^^^^^^^^ Finders can not be used inside a Finder.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Finder inside a model class method' do
|
||||
|
|
@ -24,7 +24,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::Finder do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User
|
||||
class << self
|
||||
def second_method
|
||||
|
|
@ -38,21 +38,21 @@ RSpec.describe RuboCop::Cop::CodeReuse::Finder do
|
|||
^^^^^^^^^^^^^ Finders can not be used inside model class methods.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not flag the use of a Finder in a non Finder file' do
|
||||
expect_no_offenses(<<~SOURCE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
BarFinder.new.execute
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not flag the use of a Finder in a regular class method' do
|
||||
expect_no_offenses(<<~SOURCE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class User
|
||||
class << self
|
||||
def second_method
|
||||
|
|
@ -64,6 +64,6 @@ RSpec.describe RuboCop::Cop::CodeReuse::Finder do
|
|||
FooFinder.new
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_service_class?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooService
|
||||
def execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a Service class.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Presenter in a Finder' do
|
||||
|
|
@ -24,14 +24,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_finder?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a Finder.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Service class in a Presenter' do
|
||||
|
|
@ -39,14 +39,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_presenter?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooPresenter
|
||||
def execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a Presenter.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Presenter in a Serializer' do
|
||||
|
|
@ -54,14 +54,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_serializer?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooSerializer
|
||||
def execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a Serializer.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Presenter in a model instance method' do
|
||||
|
|
@ -69,14 +69,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Base
|
||||
def execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a model.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Presenter in a model class method' do
|
||||
|
|
@ -84,14 +84,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Base
|
||||
def self.execute
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a model.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Presenter in a worker' do
|
||||
|
|
@ -99,13 +99,13 @@ RSpec.describe RuboCop::Cop::CodeReuse::Presenter do
|
|||
.to receive(:in_worker?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooWorker
|
||||
def perform
|
||||
FooPresenter.new.execute
|
||||
^^^^^^^^^^^^^^^^ Presenters can not be used in a worker.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_service_class?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooService
|
||||
def execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a Service class.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a Finder' do
|
||||
|
|
@ -24,14 +24,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_finder?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a Finder.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a Presenter' do
|
||||
|
|
@ -39,14 +39,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_presenter?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooPresenter
|
||||
def execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a Presenter.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a Serializer' do
|
||||
|
|
@ -54,14 +54,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_serializer?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooSerializer
|
||||
def execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a Serializer.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a model instance method' do
|
||||
|
|
@ -69,14 +69,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Base
|
||||
def execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a model.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a model class method' do
|
||||
|
|
@ -84,14 +84,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Base
|
||||
def self.execute
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a model.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Serializer in a worker' do
|
||||
|
|
@ -99,13 +99,13 @@ RSpec.describe RuboCop::Cop::CodeReuse::Serializer do
|
|||
.to receive(:in_worker?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooWorker
|
||||
def perform
|
||||
FooSerializer.new.execute
|
||||
^^^^^^^^^^^^^^^^^ Serializers can not be used in a worker.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
|
|||
.to receive(:in_finder?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
FooService.new.execute
|
||||
^^^^^^^^^^^^^^ Service classes can not be used in a Finder.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Service class in a Presenter' do
|
||||
|
|
@ -24,14 +24,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
|
|||
.to receive(:in_presenter?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooPresenter
|
||||
def execute
|
||||
FooService.new.execute
|
||||
^^^^^^^^^^^^^^ Service classes can not be used in a Presenter.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Service class in a Serializer' do
|
||||
|
|
@ -39,14 +39,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
|
|||
.to receive(:in_serializer?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooSerializer
|
||||
def execute
|
||||
FooService.new.execute
|
||||
^^^^^^^^^^^^^^ Service classes can not be used in a Serializer.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a Service class in a model' do
|
||||
|
|
@ -54,7 +54,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Model
|
||||
class << self
|
||||
def first
|
||||
|
|
@ -68,16 +68,16 @@ RSpec.describe RuboCop::Cop::CodeReuse::ServiceClass do
|
|||
^^^^^^^^^^^^^^ Service classes can not be used in a model.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not flag the use of a Service class in a regular class' do
|
||||
expect_no_offenses(<<~SOURCE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo
|
||||
def execute
|
||||
FooService.new.execute
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_controller?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooController
|
||||
def index
|
||||
FooWorker.perform_async
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Workers can not be used in a controller.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in an API' do
|
||||
|
|
@ -24,7 +24,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_api?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Grape::API::Instance
|
||||
resource :projects do
|
||||
get '/' do
|
||||
|
|
@ -33,7 +33,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
end
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in GraphQL' do
|
||||
|
|
@ -41,7 +41,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_graphql?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
module Mutations
|
||||
class Foo < BaseMutation
|
||||
def resolve
|
||||
|
|
@ -50,7 +50,7 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
end
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in a Finder' do
|
||||
|
|
@ -58,14 +58,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_finder?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooFinder
|
||||
def execute
|
||||
FooWorker.perform_async
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Workers can not be used in a Finder.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in a Presenter' do
|
||||
|
|
@ -73,14 +73,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_presenter?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooPresenter
|
||||
def execute
|
||||
FooWorker.perform_async
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Workers can not be used in a Presenter.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in a Serializer' do
|
||||
|
|
@ -88,14 +88,14 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_serializer?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class FooSerializer
|
||||
def execute
|
||||
FooWorker.perform_async
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Workers can not be used in a Serializer.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of a worker in a model class method' do
|
||||
|
|
@ -103,13 +103,13 @@ RSpec.describe RuboCop::Cop::CodeReuse::Worker do
|
|||
.to receive(:in_model?)
|
||||
.and_return(true)
|
||||
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class User < ActiveRecord::Base
|
||||
def self.execute
|
||||
FooWorker.perform_async
|
||||
^^^^^^^^^^^^^^^^^^^^^^^ Workers can not be used in model class methods.
|
||||
end
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,30 +5,30 @@ require_relative '../../../../rubocop/cop/database/disable_referential_integrity
|
|||
|
||||
RSpec.describe RuboCop::Cop::Database::DisableReferentialIntegrity do
|
||||
it 'does not flag the use of disable_referential_integrity with a send receiver' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
foo.disable_referential_integrity
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of disable_referential_integrity with a full definition' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
ActiveRecord::Base.connection.disable_referential_integrity
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of disable_referential_integrity with a nil receiver' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo ; disable_referential_integrity ; end
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of disable_referential_integrity when passing a block' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo ; disable_referential_integrity { :foo } ; end
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use `disable_referential_integrity`, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@ require_relative '../../../../rubocop/cop/database/establish_connection'
|
|||
|
||||
RSpec.describe RuboCop::Cop::Database::EstablishConnection do
|
||||
it 'flags the use of ActiveRecord::Base.establish_connection' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
ActiveRecord::Base.establish_connection
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of ActiveRecord::Base.establish_connection with arguments' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
ActiveRecord::Base.establish_connection(:foo)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of SomeModel.establish_connection' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
SomeModel.establish_connection
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Don't establish new database [...]
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,26 +5,26 @@ require_relative '../../../../rubocop/cop/database/multiple_databases'
|
|||
|
||||
RSpec.describe RuboCop::Cop::Database::MultipleDatabases do
|
||||
it 'flags the use of ActiveRecord::Base.connection' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
ActiveRecord::Base.connection.inspect
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use methods from ActiveRecord::Base, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'flags the use of ::ActiveRecord::Base.connection' do
|
||||
expect_offense(<<~SOURCE)
|
||||
expect_offense(<<~RUBY)
|
||||
::ActiveRecord::Base.connection.inspect
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Do not use methods from ActiveRecord::Base, [...]
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
|
||||
described_class::ALLOWED_METHODS.each do |method_name|
|
||||
it "does not flag use of ActiveRecord::Base.#{method_name}" do
|
||||
expect_no_offenses(<<~SOURCE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
ActiveRecord::Base.#{method_name} do
|
||||
Project.save
|
||||
end
|
||||
SOURCE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@ require_relative '../../../../rubocop/cop/database/rescue_query_canceled'
|
|||
|
||||
RSpec.describe RuboCop::Cop::Database::RescueQueryCanceled do
|
||||
it 'flags the use of ActiveRecord::QueryCanceled' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
begin
|
||||
do_something
|
||||
rescue ActiveRecord::QueryCanceled => e
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid rescuing the `ActiveRecord::QueryCanceled` [...]
|
||||
try_something_else
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not flag a different exception' do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
begin
|
||||
do_something
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
try_something_else
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,23 +5,23 @@ require_relative '../../../../rubocop/cop/database/rescue_statement_timeout'
|
|||
|
||||
RSpec.describe RuboCop::Cop::Database::RescueStatementTimeout do
|
||||
it 'flags the use of ActiveRecord::StatementTimeout' do
|
||||
expect_offense(<<~CODE)
|
||||
expect_offense(<<~RUBY)
|
||||
begin
|
||||
do_something
|
||||
rescue ActiveRecord::StatementTimeout => e
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid rescuing the `ActiveRecord::StatementTimeout` [...]
|
||||
try_something_else
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
|
||||
it 'does not flag a different exception' do
|
||||
expect_no_offenses(<<~CODE)
|
||||
expect_no_offenses(<<~RUBY)
|
||||
begin
|
||||
do_something
|
||||
rescue ActiveRecord::RecordNotFound => e
|
||||
try_something_else
|
||||
end
|
||||
CODE
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue