diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 12:45:46 +0300 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/lib/gitlab/database/loose_foreign_keys_spec.rb | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/lib/gitlab/database/loose_foreign_keys_spec.rb')
-rw-r--r-- | spec/lib/gitlab/database/loose_foreign_keys_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/lib/gitlab/database/loose_foreign_keys_spec.rb b/spec/lib/gitlab/database/loose_foreign_keys_spec.rb index 13f2d31bc32..ed11699e494 100644 --- a/spec/lib/gitlab/database/loose_foreign_keys_spec.rb +++ b/spec/lib/gitlab/database/loose_foreign_keys_spec.rb @@ -18,6 +18,45 @@ RSpec.describe Gitlab::Database::LooseForeignKeys do )) end + context 'ensure keys are sorted' do + it 'does not have any keys that are out of order' do + parsed = YAML.parse_file(described_class.loose_foreign_keys_yaml_path) + mapping = parsed.children.first + table_names = mapping.children.select(&:scalar?).map(&:value) + expect(table_names).to eq(table_names.sort), "expected sorted table names in the YAML file" + end + end + + context 'ensure no duplicates are found' do + it 'does not have duplicate tables defined' do + # since we use hash to detect duplicate hash keys we need to parse YAML document + parsed = YAML.parse_file(described_class.loose_foreign_keys_yaml_path) + expect(parsed).to be_document + expect(parsed.children).to be_one, "YAML has a single document" + + # require hash + mapping = parsed.children.first + expect(mapping).to be_mapping, "YAML has a top-level hash" + + # find all scalars with names + table_names = mapping.children.select(&:scalar?).map(&:value) + expect(table_names).not_to be_empty, "YAML has a non-zero tables defined" + + # expect to not have duplicates + expect(table_names).to contain_exactly(*table_names.uniq) + end + + it 'does not have duplicate column definitions' do + # ignore other modifiers + all_definitions = definitions.map do |definition| + { from_table: definition.from_table, to_table: definition.to_table, column: definition.column } + end + + # expect to not have duplicates + expect(all_definitions).to contain_exactly(*all_definitions.uniq) + end + end + describe 'ensuring database integrity' do def base_models_for(table) parent_table_schema = Gitlab::Database::GitlabSchema.table_schema(table) |