Commit fd8ae0f6 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '299410-ban-attributes_for-in-migration' into 'master'

Ban `attributes_for` for migration specs

See merge request gitlab-org/gitlab!52182
parents e7cac479 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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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,
......
...@@ -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)
......
...@@ -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,
......
...@@ -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)
......
...@@ -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)
......
...@@ -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(' ')}} ...)
......
...@@ -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
......
...@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment