diff options
Diffstat (limited to 'spec/migrations')
-rw-r--r-- | spec/migrations/ensure_namespace_settings_creation_spec.rb | 44 | ||||
-rw-r--r-- | spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb | 42 |
2 files changed, 56 insertions, 30 deletions
diff --git a/spec/migrations/ensure_namespace_settings_creation_spec.rb b/spec/migrations/ensure_namespace_settings_creation_spec.rb new file mode 100644 index 00000000000..8574063f7fe --- /dev/null +++ b/spec/migrations/ensure_namespace_settings_creation_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20201104124300_ensure_namespace_settings_creation.rb') + +RSpec.describe EnsureNamespaceSettingsCreation do + context 'when there are namespaces without namespace settings' do + let(:namespaces) { table(:namespaces) } + let(:namespace_settings) { table(:namespace_settings) } + let!(:namespace) { namespaces.create!(name: 'gitlab', path: 'gitlab-org') } + let!(:namespace_2) { namespaces.create!(name: 'gitlab', path: 'gitlab-org2') } + + it 'migrates namespaces without namespace_settings' do + stub_const("#{described_class.name}::BATCH_SIZE", 2) + + Sidekiq::Testing.fake! do + freeze_time do + migrate! + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(2.minutes.to_i, namespace.id, namespace_2.id) + end + end + end + + it 'schedules migrations in batches ' do + stub_const("#{described_class.name}::BATCH_SIZE", 2) + + namespace_3 = namespaces.create!(name: 'gitlab', path: 'gitlab-org3') + namespace_4 = namespaces.create!(name: 'gitlab', path: 'gitlab-org4') + + Sidekiq::Testing.fake! do + freeze_time do + migrate! + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(2.minutes.to_i, namespace.id, namespace_2.id) + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(4.minutes.to_i, namespace_3.id, namespace_4.id) + end + end + end + end +end diff --git a/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb b/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb index cd2ec81abb7..5c3ca281d49 100644 --- a/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb +++ b/spec/migrations/migrate_compliance_framework_enum_to_database_framework_record_spec.rb @@ -30,41 +30,23 @@ RSpec.describe MigrateComplianceFrameworkEnumToDatabaseFrameworkRecord, schema: subject { described_class.new.up } - context 'when Gitlab.ee? is true' do - before do - expect(Gitlab).to receive(:ee?).and_return(true) - end + it 'updates the project settings' do + subject - it 'updates the project settings' do - subject + gdpr_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'GDPR') + expect(project_on_root_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id) + expect(project_on_sub_sub_level_compliance_setting_2.reload.framework_id).to eq(gdpr_framework.id) - gdpr_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'GDPR') - expect(project_on_root_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id) - expect(project_on_sub_sub_level_compliance_setting_2.reload.framework_id).to eq(gdpr_framework.id) + sox_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'SOX') + expect(project_on_sub_sub_level_compliance_setting_1.reload.framework_id).to eq(sox_framework.id) - sox_framework = compliance_management_frameworks.find_by(namespace_id: root_group.id, name: 'SOX') - expect(project_on_sub_sub_level_compliance_setting_1.reload.framework_id).to eq(sox_framework.id) - - gdpr_framework = compliance_management_frameworks.find_by(namespace_id: namespace.id, name: 'GDPR') - expect(project_on_namespace_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id) - end - - it 'adds two framework records' do - subject - - expect(compliance_management_frameworks.count).to eq(3) - end + gdpr_framework = compliance_management_frameworks.find_by(namespace_id: namespace.id, name: 'GDPR') + expect(project_on_namespace_level_compliance_setting.reload.framework_id).to eq(gdpr_framework.id) end - context 'when Gitlab.ee? is false' do - before do - expect(Gitlab).to receive(:ee?).and_return(false) - end - - it 'does nothing' do - subject + it 'adds two framework records' do + subject - expect(compliance_management_frameworks.count).to eq(0) - end + expect(compliance_management_frameworks.count).to eq(3) end end |