summaryrefslogtreecommitdiff
path: root/rubocop
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2019-01-16 11:35:08 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2019-01-16 13:15:33 +0100
commit7c801333a0f2c01639ed2d4b0eb5a1008de98fdb (patch)
treedd5c960981f7fec8e9da64a86b63dfa24157654f /rubocop
parent1a77ea20edf88f828a1f36f520285a50176e6e08 (diff)
downloadgitlab-ce-7c801333a0f2c01639ed2d4b0eb5a1008de98fdb.tar.gz
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.
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/spec_helpers.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/rubocop/spec_helpers.rb b/rubocop/spec_helpers.rb
index 9bf5f1e3b18..63c1b975a65 100644
--- a/rubocop/spec_helpers.rb
+++ b/rubocop/spec_helpers.rb
@@ -1,6 +1,7 @@
module RuboCop
module SpecHelpers
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.
def in_spec?(node)
@@ -10,14 +11,18 @@ module RuboCop
path.start_with?(File.join(Dir.pwd, 'spec'), File.join(Dir.pwd, 'ee', 'spec'))
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.
def in_migration_spec?(node)
path = node.location.expression.source_buffer.name
in_spec?(node) &&
- path.start_with?(
- File.join(Dir.pwd, 'spec', 'migrations'),
- File.join(Dir.pwd, 'ee', 'spec', 'migrations'))
+ path.start_with?(*migration_directories)
end
end
end