From f234d9f12d6a054412067b955d3b765325d4ccc6 Mon Sep 17 00:00:00 2001
From: Heinrich Lee Yu <heinrich@gitlab.com>
Date: Thu, 28 Mar 2019 05:48:53 +0800
Subject: [PATCH] Properly handle `ee` migration specs

---
 .../cop/migration/update_column_in_batches.rb  |  2 +-
 .../migration/update_column_in_batches_spec.rb | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/rubocop/cop/migration/update_column_in_batches.rb b/rubocop/cop/migration/update_column_in_batches.rb
index 5461abc5ee00f..b1c43393f6a90 100644
--- a/rubocop/cop/migration/update_column_in_batches.rb
+++ b/rubocop/cop/migration/update_column_in_batches.rb
@@ -28,7 +28,7 @@ def spec_filename(node)
           source_name = node.location.expression.source_buffer.name
           path = Pathname.new(source_name).relative_path_from(rails_root)
           dirname = File.dirname(path)
-            .sub(%r{\Adb/(migrate|post_migrate)}, 'spec/migrations')
+            .sub(%r{db/(migrate|post_migrate)}, 'spec/migrations')
           filename = File.basename(source_name, '.rb').sub(/\A\d+_/, '')
 
           File.join(dirname, "#{filename}_spec.rb")
diff --git a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
index 1c8ab0ad5d2fc..cba01400d85eb 100644
--- a/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
+++ b/spec/rubocop/cop/migration/update_column_in_batches_spec.rb
@@ -93,4 +93,22 @@ def up
     it_behaves_like 'a migration file with no spec file'
     it_behaves_like 'a migration file with a spec file'
   end
+
+  context 'EE migrations' do
+    let(:spec_filepath) { tmp_rails_root.join('ee', 'spec', 'migrations', 'my_super_migration_spec.rb') }
+
+    context 'in a migration' do
+      let(:migration_filepath) { tmp_rails_root.join('ee', 'db', 'migrate', '20121220064453_my_super_migration.rb') }
+
+      it_behaves_like 'a migration file with no spec file'
+      it_behaves_like 'a migration file with a spec file'
+    end
+
+    context 'in a post migration' do
+      let(:migration_filepath) { tmp_rails_root.join('ee', 'db', 'post_migrate', '20121220064453_my_super_migration.rb') }
+
+      it_behaves_like 'a migration file with no spec file'
+      it_behaves_like 'a migration file with a spec file'
+    end
+  end
 end
-- 
GitLab