Commit 28b459dd authored by Alexandru Croitor's avatar Alexandru Croitor Committed by Adam Hegyi

Allow modules in class names of batched migrations

parent ab991fa8
...@@ -94,11 +94,11 @@ module Gitlab ...@@ -94,11 +94,11 @@ module Gitlab
end end
def job_class_name=(class_name) def job_class_name=(class_name)
write_attribute(:job_class_name, class_name.demodulize) write_attribute(:job_class_name, class_name.delete_prefix("::"))
end end
def batch_class_name=(class_name) def batch_class_name=(class_name)
write_attribute(:batch_class_name, class_name.demodulize) write_attribute(:batch_class_name, class_name.delete_prefix("::"))
end end
def migrated_tuple_count def migrated_tuple_count
......
...@@ -236,14 +236,20 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m ...@@ -236,14 +236,20 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m
end end
end end
shared_examples_for 'an attr_writer that demodulizes assigned class names' do |attribute_name| shared_examples_for 'an attr_writer that assigns class names' do |attribute_name|
let(:batched_migration) { build(:batched_background_migration) } let(:batched_migration) { build(:batched_background_migration) }
context 'when a module name exists' do context 'when a module name exists' do
it 'removes the module name' do it 'keeps the class with module name' do
batched_migration.public_send(:"#{attribute_name}=", 'Foo::Bar')
expect(batched_migration[attribute_name]).to eq('Foo::Bar')
end
it 'removes leading namespace resolution operator' do
batched_migration.public_send(:"#{attribute_name}=", '::Foo::Bar') batched_migration.public_send(:"#{attribute_name}=", '::Foo::Bar')
expect(batched_migration[attribute_name]).to eq('Bar') expect(batched_migration[attribute_name]).to eq('Foo::Bar')
end end
end end
...@@ -293,11 +299,11 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m ...@@ -293,11 +299,11 @@ RSpec.describe Gitlab::Database::BackgroundMigration::BatchedMigration, type: :m
end end
describe '#job_class_name=' do describe '#job_class_name=' do
it_behaves_like 'an attr_writer that demodulizes assigned class names', :job_class_name it_behaves_like 'an attr_writer that assigns class names', :job_class_name
end end
describe '#batch_class_name=' do describe '#batch_class_name=' do
it_behaves_like 'an attr_writer that demodulizes assigned class names', :batch_class_name it_behaves_like 'an attr_writer that assigns class names', :batch_class_name
end end
describe '#migrated_tuple_count' do describe '#migrated_tuple_count' 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