Commit 7c801333 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Prevent factories in background migration specs

The Background migration specs also run against a certain version of
the database. So we should avoid using factories.
parent 1a77ea20
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
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