Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/database/partitioning_migration_helpers/partitioned_foreign_key_spec.rb')
-rw-r--r--spec/lib/gitlab/database/partitioning_migration_helpers/partitioned_foreign_key_spec.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/partitioning_migration_helpers/partitioned_foreign_key_spec.rb b/spec/lib/gitlab/database/partitioning_migration_helpers/partitioned_foreign_key_spec.rb
new file mode 100644
index 00000000000..77f71676252
--- /dev/null
+++ b/spec/lib/gitlab/database/partitioning_migration_helpers/partitioned_foreign_key_spec.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Database::PartitioningMigrationHelpers::PartitionedForeignKey do
+ let(:foreign_key) do
+ described_class.new(
+ to_table: 'issues',
+ from_table: 'issue_assignees',
+ from_column: 'issue_id',
+ to_column: 'id',
+ cascade_delete: true)
+ end
+
+ describe 'validations' do
+ it 'allows keys that reference valid tables and columns' do
+ expect(foreign_key).to be_valid
+ end
+
+ it 'does not allow keys without a valid to_table' do
+ foreign_key.to_table = 'this_is_not_a_real_table'
+
+ expect(foreign_key).not_to be_valid
+ expect(foreign_key.errors[:to_table].first).to eq('must be a valid table')
+ end
+
+ it 'does not allow keys without a valid from_table' do
+ foreign_key.from_table = 'this_is_not_a_real_table'
+
+ expect(foreign_key).not_to be_valid
+ expect(foreign_key.errors[:from_table].first).to eq('must be a valid table')
+ end
+
+ it 'does not allow keys without a valid to_column' do
+ foreign_key.to_column = 'this_is_not_a_real_fk'
+
+ expect(foreign_key).not_to be_valid
+ expect(foreign_key.errors[:to_column].first).to eq('must be a valid column')
+ end
+
+ it 'does not allow keys without a valid from_column' do
+ foreign_key.from_column = 'this_is_not_a_real_pk'
+
+ expect(foreign_key).not_to be_valid
+ expect(foreign_key.errors[:from_column].first).to eq('must be a valid column')
+ end
+ end
+end