diff options
Diffstat (limited to 'spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb')
-rw-r--r-- | spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb b/spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb new file mode 100644 index 00000000000..a28ca12a10d --- /dev/null +++ b/spec/migrations/remove_records_without_group_from_webhooks_table_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' + +require_migration! +require Rails.root.join('db', 'migrate', '20210325092215_add_not_valid_foreign_key_to_group_hooks.rb') + +RSpec.describe RemoveRecordsWithoutGroupFromWebhooksTable, schema: 20210330091751 do + let(:web_hooks) { table(:web_hooks) } + let(:groups) { table(:namespaces) } + + before do + group = groups.create!(name: 'gitlab', path: 'gitlab-org') + web_hooks.create!(group_id: group.id, type: 'GroupHook') + web_hooks.create!(group_id: nil) + + AddNotValidForeignKeyToGroupHooks.new.down + web_hooks.create!(group_id: non_existing_record_id, type: 'GroupHook') + AddNotValidForeignKeyToGroupHooks.new.up + end + + it 'removes group hooks where the referenced group does not exist', :aggregate_failures do + expect { RemoveRecordsWithoutGroupFromWebhooksTable.new.up }.to change { web_hooks.count }.by(-1) + expect(web_hooks.where.not(group_id: groups.select(:id)).count).to eq(0) + expect(web_hooks.where.not(group_id: nil).count).to eq(1) + end +end |