Commit 5f55f711 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'bvl-dont-use-factories-in-bg-migration-specs' into 'master'

Enable FactoriesInMigration cop for background migration specs

See merge request gitlab-org/gitlab-ee!9183
parents d683bf11 d13dc59a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRulesInBatch do describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRulesInBatch do
context 'when there is no more MigrateApproverToApprovalRules jobs' do context 'when there is no more MigrateApproverToApprovalRules jobs' do
let(:job) { double(:job) } let(:job) { double(:job) }
...@@ -18,3 +19,4 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRulesInBatch do ...@@ -18,3 +19,4 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRulesInBatch do
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do
def create_skip_sync(*args) def create_skip_sync(*args)
build(*args) do |record| build(*args) do |record|
...@@ -242,3 +243,4 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do ...@@ -242,3 +243,4 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
let(:background_migration) { described_class.new } let(:background_migration) { described_class.new }
...@@ -90,3 +91,4 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do ...@@ -90,3 +91,4 @@ describe Gitlab::BackgroundMigration::UpdateAuthorizedKeysFileSince do
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
module RuboCop module RuboCop
module SpecHelpers module SpecHelpers
SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze SPEC_HELPERS = %w[fast_spec_helper.rb rails_helper.rb spec_helper.rb].freeze
MIGRATION_SPEC_DIRECTORIES = ['spec/migrations', 'spec/lib/gitlab/background_migration'].freeze
# Returns true if the given node originated from the spec directory. # Returns true if the given node originated from the spec directory.
def in_spec?(node) def in_spec?(node)
...@@ -10,14 +11,18 @@ module RuboCop ...@@ -10,14 +11,18 @@ module RuboCop
path.start_with?(File.join(Dir.pwd, 'spec'), File.join(Dir.pwd, 'ee', 'spec')) path.start_with?(File.join(Dir.pwd, 'spec'), File.join(Dir.pwd, 'ee', 'spec'))
end end
def migration_directories
@migration_directories ||= MIGRATION_SPEC_DIRECTORIES.map do |dir|
[File.join(Dir.pwd, dir), File.join(Dir.pwd, 'ee', dir)]
end.flatten
end
# Returns true if the given node originated from a migration spec. # Returns true if the given node originated from a migration spec.
def in_migration_spec?(node) def in_migration_spec?(node)
path = node.location.expression.source_buffer.name path = node.location.expression.source_buffer.name
in_spec?(node) && in_spec?(node) &&
path.start_with?( path.start_with?(*migration_directories)
File.join(Dir.pwd, 'spec', 'migrations'),
File.join(Dir.pwd, 'ee', 'spec', 'migrations'))
end end
end end
end end
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::BackfillProjectRepositories do describe Gitlab::BackgroundMigration::BackfillProjectRepositories do
let(:group) { create(:group, name: 'foo', path: 'foo') } let(:group) { create(:group, name: 'foo', path: 'foo') }
...@@ -102,3 +103,4 @@ describe Gitlab::BackgroundMigration::BackfillProjectRepositories do ...@@ -102,3 +103,4 @@ describe Gitlab::BackgroundMigration::BackfillProjectRepositories do
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
...@@ -2,7 +2,7 @@ require 'spec_helper' ...@@ -2,7 +2,7 @@ require 'spec_helper'
describe Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys, :migration, schema: 20171005130944 do describe Gitlab::BackgroundMigration::CreateGpgKeySubkeysFromGpgKeys, :migration, schema: 20171005130944 do
context 'when GpgKey exists' do context 'when GpgKey exists' do
let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) } let!(:gpg_key) { create(:gpg_key, key: GpgHelpers::User3.public_key) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
before do before do
GpgKeySubkey.destroy_all # rubocop: disable DestroyAll GpgKeySubkey.destroy_all # rubocop: disable DestroyAll
......
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, schema: 20180619121030 do describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, schema: 20180619121030 do
describe '#perform' do describe '#perform' do
context 'when diff files can be deleted' do context 'when diff files can be deleted' do
...@@ -71,3 +72,4 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch ...@@ -71,3 +72,4 @@ describe Gitlab::BackgroundMigration::DeleteDiffFiles, :migration, :sidekiq, sch
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :migration, schema: 20171114162227 do describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :migration, schema: 20171114162227 do
include GitHelpers include GitHelpers
...@@ -324,3 +325,4 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m ...@@ -324,3 +325,4 @@ describe Gitlab::BackgroundMigration::DeserializeMergeRequestDiffsAndCommits, :m
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads::Event, :migration, schema: 20170608152748 do describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads::Event, :migration, schema: 20170608152748 do
describe '#commit_title' do describe '#commit_title' do
it 'returns nil when there are no commits' do it 'returns nil when there are no commits' do
...@@ -429,3 +430,4 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads, :migrati ...@@ -429,3 +430,4 @@ describe Gitlab::BackgroundMigration::MigrateEventsToPushEventPayloads, :migrati
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::MigrateSystemUploadsToNewFolder, :delete do describe Gitlab::BackgroundMigration::MigrateSystemUploadsToNewFolder, :delete do
let(:migration) { described_class.new } let(:migration) { described_class.new }
...@@ -17,3 +18,4 @@ describe Gitlab::BackgroundMigration::MigrateSystemUploadsToNewFolder, :delete d ...@@ -17,3 +18,4 @@ describe Gitlab::BackgroundMigration::MigrateSystemUploadsToNewFolder, :delete d
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::MovePersonalSnippetFiles do describe Gitlab::BackgroundMigration::MovePersonalSnippetFiles do
let(:test_dir) { File.join(Rails.root, 'tmp', 'tests', 'move_snippet_files_test') } let(:test_dir) { File.join(Rails.root, 'tmp', 'tests', 'move_snippet_files_test') }
let(:old_uploads_dir) { File.join('uploads', 'system', 'personal_snippet') } let(:old_uploads_dir) { File.join('uploads', 'system', 'personal_snippet') }
...@@ -70,3 +71,4 @@ describe Gitlab::BackgroundMigration::MovePersonalSnippetFiles do ...@@ -70,3 +71,4 @@ describe Gitlab::BackgroundMigration::MovePersonalSnippetFiles do
"[an upload](#{path})" "[an upload](#{path})"
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, :migration, schema: 20181022173835 do describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, :migration, schema: 20181022173835 do
let(:migration) { described_class.new } let(:migration) { described_class.new }
let(:clusters) { create_list(:cluster, 10, :project, :provided_by_gcp) } let(:clusters) { create_list(:cluster, 10, :project, :provided_by_gcp) }
...@@ -95,3 +96,4 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, : ...@@ -95,3 +96,4 @@ describe Gitlab::BackgroundMigration::PopulateClusterKubernetesNamespaceTable, :
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require 'spec_helper' require 'spec_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration, schema: 20180916011959 do
let(:migration) { described_class.new } let(:migration) { described_class.new }
...@@ -65,3 +66,4 @@ describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration ...@@ -65,3 +66,4 @@ describe Gitlab::BackgroundMigration::PopulateExternalPipelineSource, :migration
it_behaves_like 'no changes' it_behaves_like 'no changes'
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
require 'rails_helper' require 'rails_helper'
# rubocop:disable RSpec/FactoriesInMigrationSpecs
describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData, :migration, schema: 20171128214150 do describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData, :migration, schema: 20171128214150 do
# commits_count attribute is added in a next migration # commits_count attribute is added in a next migration
before do before do
...@@ -128,3 +129,4 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData, ...@@ -128,3 +129,4 @@ describe Gitlab::BackgroundMigration::PopulateMergeRequestMetricsWithEventsData,
end end
end end
end end
# rubocop:enable RSpec/FactoriesInMigrationSpecs
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