summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/database/migration_helpers_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-08 15:08:01 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-08 15:08:01 +0000
commita7df1d8717d39424ced032d9fe063f08f97e19d6 (patch)
treef887841557b509e950475176baa4d405bfd411f4 /spec/lib/gitlab/database/migration_helpers_spec.rb
parente3e300557f5def9bf2271735c8a620e6820dfada (diff)
downloadgitlab-ce-a7df1d8717d39424ced032d9fe063f08f97e19d6.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/database/migration_helpers_spec.rb')
-rw-r--r--spec/lib/gitlab/database/migration_helpers_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb
index 9c8d53b0ed7..439f1343514 100644
--- a/spec/lib/gitlab/database/migration_helpers_spec.rb
+++ b/spec/lib/gitlab/database/migration_helpers_spec.rb
@@ -347,6 +347,48 @@ describe Gitlab::Database::MigrationHelpers do
end
end
+ describe '#validate_foreign_key' do
+ context 'when name is provided' do
+ it 'does not infer the foreign key constraint name' do
+ expect(model).to receive(:foreign_key_exists?).with(:projects, name: :foo).and_return(true)
+
+ aggregate_failures do
+ expect(model).not_to receive(:concurrent_foreign_key_name)
+ expect(model).to receive(:disable_statement_timeout).and_call_original
+ expect(model).to receive(:execute).with(/statement_timeout/)
+ expect(model).to receive(:execute).ordered.with(/ALTER TABLE projects VALIDATE CONSTRAINT/)
+ expect(model).to receive(:execute).ordered.with(/RESET ALL/)
+ end
+
+ model.validate_foreign_key(:projects, :user_id, name: :foo)
+ end
+ end
+
+ context 'when name is not provided' do
+ it 'infers the foreign key constraint name' do
+ expect(model).to receive(:foreign_key_exists?).with(:projects, name: anything).and_return(true)
+
+ aggregate_failures do
+ expect(model).to receive(:concurrent_foreign_key_name)
+ expect(model).to receive(:disable_statement_timeout).and_call_original
+ expect(model).to receive(:execute).with(/statement_timeout/)
+ expect(model).to receive(:execute).ordered.with(/ALTER TABLE projects VALIDATE CONSTRAINT/)
+ expect(model).to receive(:execute).ordered.with(/RESET ALL/)
+ end
+
+ model.validate_foreign_key(:projects, :user_id)
+ end
+
+ context 'when the inferred foreign key constraint does not exist' do
+ it 'raises an error' do
+ expect(model).to receive(:foreign_key_exists?).and_return(false)
+
+ expect { model.validate_foreign_key(:projects, :user_id) }.to raise_error(/cannot find/)
+ end
+ end
+ end
+ end
+
describe '#concurrent_foreign_key_name' do
it 'returns the name for a foreign key' do
name = model.concurrent_foreign_key_name(:this_is_a_very_long_table_name,