diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 18:08:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 18:08:01 +0300 |
commit | a7df1d8717d39424ced032d9fe063f08f97e19d6 (patch) | |
tree | f887841557b509e950475176baa4d405bfd411f4 /spec/lib/gitlab/database | |
parent | e3e300557f5def9bf2271735c8a620e6820dfada (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/database')
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 42 |
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, |