diff options
Diffstat (limited to 'spec/lib/gitlab')
4 files changed, 57 insertions, 12 deletions
diff --git a/spec/lib/gitlab/database/dictionary_spec.rb b/spec/lib/gitlab/database/dictionary_spec.rb index 59145842b24..2a7535ffb23 100644 --- a/spec/lib/gitlab/database/dictionary_spec.rb +++ b/spec/lib/gitlab/database/dictionary_spec.rb @@ -3,10 +3,12 @@ require 'spec_helper' RSpec.describe Gitlab::Database::Dictionary, feature_category: :database do + subject(:dictionary) { described_class.entries('') } + describe '.entries' do it 'all tables and views are unique' do - table_and_view_names = described_class.entries('') - table_and_view_names += described_class.entries('views') + table_and_view_names = dictionary.to_a + table_and_view_names += described_class.entries('views').to_a # ignore gitlab_internal due to `ar_internal_metadata`, `schema_migrations` table_and_view_names = table_and_view_names @@ -22,6 +24,51 @@ RSpec.describe Gitlab::Database::Dictionary, feature_category: :database do "Any duplicated table must be removed from db/docs/ or ee/db/docs/. " \ "More info: https://docs.gitlab.com/ee/development/database/database_dictionary.html" end + + it 'builds a Dictionary with validated Entry records' do + expect { dictionary }.not_to raise_error + + expect(dictionary).to be_instance_of(described_class) + expect(dictionary).to all(be_instance_of(Gitlab::Database::Dictionary::Entry)) + end + end + + describe '#to_name_and_schema_mapping' do + it 'returns a hash of name and schema mappings' do + expect(dictionary.to_name_and_schema_mapping).to include( + { + 'application_settings' => :gitlab_main_clusterwide, + 'members' => :gitlab_main_cell + } + ) + end + end + + describe '#find_by_table_name' do + it 'finds an entry by table name' do + entry = dictionary.find_by_table_name('application_settings') + expect(entry).to be_instance_of(Gitlab::Database::Dictionary::Entry) + expect(entry.key_name).to eq('application_settings') + expect(entry.gitlab_schema).to eq('gitlab_main_clusterwide') + end + + it 'returns nil if the entry is not found' do + entry = dictionary.find_by_table_name('non_existent_table') + expect(entry).to be_nil + end + end + + describe '#find_all_by_schema' do + it 'returns an array of entries with a given schema' do + entries = dictionary.find_all_by_schema('gitlab_main_cell') + expect(entries).to all(be_instance_of(Gitlab::Database::Dictionary::Entry)) + expect(entries).to all(have_attributes(gitlab_schema: 'gitlab_main_cell')) + end + + it 'returns an empty array if no entries match the schema' do + entries = dictionary.find_all_by_schema('non_existent_schema') + expect(entries).to be_empty + end end describe '.any_entry' do diff --git a/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb b/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb index 4fc62c6cc74..09cf7808042 100644 --- a/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb +++ b/spec/lib/gitlab/database/no_new_tables_with_gitlab_main_schema_spec.rb @@ -51,16 +51,12 @@ RSpec.describe 'new tables with gitlab_main schema', feature_category: :cell do end def tables_having_gitlab_main_schema(starting_from_milestone:) - selected_data = gitlab_main_schema_tables.select do |entry| - entry.milestone.to_f >= starting_from_milestone + gitlab_main_schema_tables.filter_map do |entry| + entry.table_name if entry.milestone.to_f >= starting_from_milestone end - - selected_data.map(&:table_name) end def gitlab_main_schema_tables - ::Gitlab::Database::Dictionary.entries.select do |entry| - entry.schema?('gitlab_main') - end + ::Gitlab::Database::Dictionary.entries.find_all_by_schema('gitlab_main') end end diff --git a/spec/lib/gitlab/database/sharding_key_spec.rb b/spec/lib/gitlab/database/sharding_key_spec.rb index 67c1422af3c..dfd78bfacba 100644 --- a/spec/lib/gitlab/database/sharding_key_spec.rb +++ b/spec/lib/gitlab/database/sharding_key_spec.rb @@ -108,11 +108,11 @@ RSpec.describe 'new tables missing sharding_key', feature_category: :cell do end def tables_missing_sharding_key(starting_from_milestone:) - ::Gitlab::Database::Dictionary.entries.select do |entry| - entry.sharding_key.blank? && + ::Gitlab::Database::Dictionary.entries.filter_map do |entry| + entry.table_name if entry.sharding_key.blank? && entry.milestone.to_f >= starting_from_milestone && ::Gitlab::Database::GitlabSchema.cell_local?(entry.gitlab_schema) - end.map(&:table_name) + end end def all_tables_to_sharding_key diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 8da05ed7b7e..6d5c17176dc 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -176,6 +176,7 @@ project_members: - project - member_namespace - member_role +- member_approvals member_roles: - members - namespace @@ -838,6 +839,7 @@ project: - organization - dora_performance_scores - xray_reports +- member_approvals award_emoji: - awardable - user |