Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ab85b805
Commit
ab85b805
authored
Jan 21, 2021
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ban attributes_for for migration specs
We'll rewrite the offenders later.
parent
ba4bac42
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
23 additions
and
23 deletions
+23
-23
ee/spec/lib/ee/gitlab/background_migration/remove_duplicate_cs_findings_spec.rb
...background_migration/remove_duplicate_cs_findings_spec.rb
+1
-1
ee/spec/lib/ee/gitlab/background_migration/remove_duplicated_cs_findings_without_vulnerability_id_spec.rb
...e_duplicated_cs_findings_without_vulnerability_id_spec.rb
+1
-1
ee/spec/lib/ee/gitlab/background_migration/remove_undefined_occurrence_confidence_level_spec.rb
...tion/remove_undefined_occurrence_confidence_level_spec.rb
+1
-1
ee/spec/lib/ee/gitlab/background_migration/remove_undefined_occurrence_severity_level_spec.rb
...ration/remove_undefined_occurrence_severity_level_spec.rb
+1
-1
ee/spec/lib/ee/gitlab/background_migration/update_location_fingerprint_for_container_scanning_findings_spec.rb
...ation_fingerprint_for_container_scanning_findings_spec.rb
+1
-1
ee/spec/lib/ee/gitlab/background_migration/update_vulnerability_confidence_spec.rb
...kground_migration/update_vulnerability_confidence_spec.rb
+1
-1
ee/spec/migrations/remove_duplicated_cs_findings_spec.rb
ee/spec/migrations/remove_duplicated_cs_findings_spec.rb
+1
-1
ee/spec/migrations/remove_duplicated_cs_findings_without_vulnerability_id_spec.rb
...e_duplicated_cs_findings_without_vulnerability_id_spec.rb
+1
-1
ee/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb
...rations/update_cs_vulnerability_confidence_column_spec.rb
+2
-2
ee/spec/migrations/update_location_fingerprint_column_for_cs_spec.rb
...rations/update_location_fingerprint_column_for_cs_spec.rb
+1
-1
ee/spec/migrations/update_occurrence_severity_column_spec.rb
ee/spec/migrations/update_occurrence_severity_column_spec.rb
+2
-2
ee/spec/migrations/update_undefined_confidence_from_occurrences_spec.rb
...ions/update_undefined_confidence_from_occurrences_spec.rb
+3
-2
rubocop/cop/rspec/factories_in_migration_specs.rb
rubocop/cop/rspec/factories_in_migration_specs.rb
+1
-1
spec/migrations/schedule_migrate_security_scans_spec.rb
spec/migrations/schedule_migrate_security_scans_spec.rb
+5
-6
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
+1
-1
No files found.
ee/spec/lib/ee/gitlab/background_migration/remove_duplicate_cs_findings_spec.rb
View file @
ab85b805
...
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateCsFindings, :migratio
...
@@ -106,7 +106,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicateCsFindings, :migratio
end
end
def
finding_params
(
primary_identifier_id
,
project_id
)
def
finding_params
(
primary_identifier_id
,
project_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/lib/ee/gitlab/background_migration/remove_duplicated_cs_findings_without_vulnerability_id_spec.rb
View file @
ab85b805
...
@@ -76,7 +76,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul
...
@@ -76,7 +76,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveDuplicatedCsFindingsWithoutVul
end
end
def
finding_params
(
primary_identifier_id
,
project_id
)
def
finding_params
(
primary_identifier_id
,
project_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/lib/ee/gitlab/background_migration/remove_undefined_occurrence_confidence_level_spec.rb
View file @
ab85b805
...
@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceConfidenceL
...
@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceConfidenceL
end
end
def
vuln_params
(
primary_identifier_id
)
def
vuln_params
(
primary_identifier_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
confidence:
0
,
confidence:
0
,
...
...
ee/spec/lib/ee/gitlab/background_migration/remove_undefined_occurrence_severity_level_spec.rb
View file @
ab85b805
...
@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceSeverityLev
...
@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration::RemoveUndefinedOccurrenceSeverityLev
end
end
def
vuln_params
(
primary_identifier_id
)
def
vuln_params
(
primary_identifier_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
...
...
ee/spec/lib/ee/gitlab/background_migration/update_location_fingerprint_for_container_scanning_findings_spec.rb
View file @
ab85b805
...
@@ -82,7 +82,7 @@ RSpec.describe Gitlab::BackgroundMigration::UpdateLocationFingerprintForContaine
...
@@ -82,7 +82,7 @@ RSpec.describe Gitlab::BackgroundMigration::UpdateLocationFingerprintForContaine
end
end
def
finding_params
(
primary_identifier_id
)
def
finding_params
(
primary_identifier_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/lib/ee/gitlab/background_migration/update_vulnerability_confidence_spec.rb
View file @
ab85b805
...
@@ -36,7 +36,7 @@ RSpec.describe Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence, schem
...
@@ -36,7 +36,7 @@ RSpec.describe Gitlab::BackgroundMigration::UpdateVulnerabilityConfidence, schem
end
end
def
container_scanning_vuln_params
(
primary_identifier_id
)
def
container_scanning_vuln_params
(
primary_identifier_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
2
,
severity:
2
,
...
...
ee/spec/migrations/remove_duplicated_cs_findings_spec.rb
View file @
ab85b805
...
@@ -90,7 +90,7 @@ RSpec.describe RemoveDuplicatedCsFindings, :migration do
...
@@ -90,7 +90,7 @@ RSpec.describe RemoveDuplicatedCsFindings, :migration do
end
end
def
finding_params
(
primary_identifier_id
,
project_id
)
def
finding_params
(
primary_identifier_id
,
project_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/migrations/remove_duplicated_cs_findings_without_vulnerability_id_spec.rb
View file @
ab85b805
...
@@ -99,7 +99,7 @@ RSpec.describe RemoveDuplicatedCsFindingsWithoutVulnerabilityId, :migration do
...
@@ -99,7 +99,7 @@ RSpec.describe RemoveDuplicatedCsFindingsWithoutVulnerabilityId, :migration do
end
end
def
finding_params
(
primary_identifier_id
,
project_id
)
def
finding_params
(
primary_identifier_id
,
project_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/migrations/update_cs_vulnerability_confidence_column_spec.rb
View file @
ab85b805
...
@@ -8,8 +8,8 @@ RSpec.describe UpdateCsVulnerabilityConfidenceColumn do
...
@@ -8,8 +8,8 @@ RSpec.describe UpdateCsVulnerabilityConfidenceColumn do
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
before
do
before
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
...
...
ee/spec/migrations/update_location_fingerprint_column_for_cs_spec.rb
View file @
ab85b805
...
@@ -77,7 +77,7 @@ RSpec.describe UpdateLocationFingerprintColumnForCs, :migration do
...
@@ -77,7 +77,7 @@ RSpec.describe UpdateLocationFingerprintColumnForCs, :migration do
end
end
def
finding_params
(
primary_identifier_id
)
def
finding_params
(
primary_identifier_id
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
attrs
=
attributes_for
(
:vulnerabilities_finding
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
{
{
severity:
0
,
severity:
0
,
confidence:
5
,
confidence:
5
,
...
...
ee/spec/migrations/update_occurrence_severity_column_spec.rb
View file @
ab85b805
...
@@ -8,8 +8,8 @@ RSpec.describe UpdateOccurrenceSeverityColumn do
...
@@ -8,8 +8,8 @@ RSpec.describe UpdateOccurrenceSeverityColumn do
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
before
do
before
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
...
...
ee/spec/migrations/update_undefined_confidence_from_occurrences_spec.rb
View file @
ab85b805
...
@@ -8,8 +8,9 @@ RSpec.describe UpdateUndefinedConfidenceFromOccurrences, :migration do
...
@@ -8,8 +8,9 @@ RSpec.describe UpdateUndefinedConfidenceFromOccurrences, :migration do
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:identifiers
)
{
table
(
:vulnerability_identifiers
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:scanners
)
{
table
(
:vulnerability_scanners
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul1
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
1
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
let
(
:vul2
)
{
attributes_for
(
:vulnerabilities_finding
,
id:
2
,
report_type:
2
,
confidence:
5
)
}
# rubocop: disable RSpec/FactoriesInMigrationSpecs
before
do
before
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
...
...
rubocop/cop/rspec/factories_in_migration_specs.rb
View file @
ab85b805
...
@@ -15,7 +15,7 @@ module RuboCop
...
@@ -15,7 +15,7 @@ module RuboCop
# let(:user) { users.create!(name: 'User 1', username: 'user1') }
# let(:user) { users.create!(name: 'User 1', username: 'user1') }
class
FactoriesInMigrationSpecs
<
RuboCop
::
Cop
::
Cop
class
FactoriesInMigrationSpecs
<
RuboCop
::
Cop
::
Cop
MESSAGE
=
"Don't use FactoryBot.%s in migration specs, use `table` instead."
.
freeze
MESSAGE
=
"Don't use FactoryBot.%s in migration specs, use `table` instead."
.
freeze
FORBIDDEN_METHODS
=
%i[build build_list create create_list]
.
freeze
FORBIDDEN_METHODS
=
%i[build build_list create create_list
attributes_for
]
.
freeze
def_node_search
:forbidden_factory_usage?
,
<<~
PATTERN
def_node_search
:forbidden_factory_usage?
,
<<~
PATTERN
(send {(const nil? :FactoryBot) nil?} {
#{
FORBIDDEN_METHODS
.
map
(
&
:inspect
).
join
(
' '
)
}
} ...)
(send {(const nil? :FactoryBot) nil?} {
#{
FORBIDDEN_METHODS
.
map
(
&
:inspect
).
join
(
' '
)
}
} ...)
...
...
spec/migrations/schedule_migrate_security_scans_spec.rb
View file @
ab85b805
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
require
'spec_helper'
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200217225719_schedule_migrate_security_scans.rb'
)
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20200217225719_schedule_migrate_security_scans.rb'
)
# rubocop: disable RSpec/FactoriesInMigrationSpecs
RSpec
.
describe
ScheduleMigrateSecurityScans
,
:sidekiq
do
RSpec
.
describe
ScheduleMigrateSecurityScans
,
:sidekiq
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:migration
)
{
described_class
.
new
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
...
@@ -13,7 +12,7 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
...
@@ -13,7 +12,7 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
let
(
:namespace
)
{
namespaces
.
create!
(
name:
"foo"
,
path:
"bar"
)
}
let
(
:namespace
)
{
namespaces
.
create!
(
name:
"foo"
,
path:
"bar"
)
}
let
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let
(
:project
)
{
projects
.
create!
(
namespace_id:
namespace
.
id
)
}
let
(
:
build
)
{
builds
.
create!
}
let
(
:
job
)
{
builds
.
create!
}
before
do
before
do
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
1
)
stub_const
(
"
#{
described_class
.
name
}
::BATCH_SIZE"
,
1
)
...
@@ -35,8 +34,8 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
...
@@ -35,8 +34,8 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
end
end
context
'has security job artifacts'
do
context
'has security job artifacts'
do
let!
(
:job_artifact_1
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
build
.
id
,
file_type:
5
)
}
let!
(
:job_artifact_1
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
job
.
id
,
file_type:
5
)
}
let!
(
:job_artifact_2
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
build
.
id
,
file_type:
8
)
}
let!
(
:job_artifact_2
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
job
.
id
,
file_type:
8
)
}
it
'schedules migration of security scans'
do
it
'schedules migration of security scans'
do
Sidekiq
::
Testing
.
fake!
do
Sidekiq
::
Testing
.
fake!
do
...
@@ -52,8 +51,8 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
...
@@ -52,8 +51,8 @@ RSpec.describe ScheduleMigrateSecurityScans, :sidekiq do
end
end
context
'has non-security job artifacts'
do
context
'has non-security job artifacts'
do
let!
(
:job_artifact_1
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
build
.
id
,
file_type:
4
)
}
let!
(
:job_artifact_1
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
job
.
id
,
file_type:
4
)
}
let!
(
:job_artifact_2
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
build
.
id
,
file_type:
9
)
}
let!
(
:job_artifact_2
)
{
job_artifacts
.
create!
(
project_id:
project
.
id
,
job_id:
job
.
id
,
file_type:
9
)
}
it
'schedules migration of security scans'
do
it
'schedules migration of security scans'
do
Sidekiq
::
Testing
.
fake!
do
Sidekiq
::
Testing
.
fake!
do
...
...
spec/rubocop/cop/rspec/factories_in_migration_specs_spec.rb
View file @
ab85b805
...
@@ -13,7 +13,7 @@ RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
...
@@ -13,7 +13,7 @@ RSpec.describe RuboCop::Cop::RSpec::FactoriesInMigrationSpecs do
subject
(
:cop
)
{
described_class
.
new
}
subject
(
:cop
)
{
described_class
.
new
}
shared_examples
'an offensive factory call'
do
|
namespace
|
shared_examples
'an offensive factory call'
do
|
namespace
|
%i[build build_list create create_list]
.
each
do
|
forbidden_method
|
%i[build build_list create create_list
attributes_for
]
.
each
do
|
forbidden_method
|
namespaced_forbidden_method
=
"
#{
namespace
}#{
forbidden_method
}
(:user)"
namespaced_forbidden_method
=
"
#{
namespace
}#{
forbidden_method
}
(:user)"
it
"registers an offense for
#{
namespaced_forbidden_method
}
"
do
it
"registers an offense for
#{
namespaced_forbidden_method
}
"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment