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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-03 09:09:20 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-03 09:09:20 +0300
commit9e7d45afd74a71be22c2413f4857d4389e360a42 (patch)
tree12474da5eb7b1afae32b83cad24fc19c13a58662 /spec
parent6577e5711222dc3b4199588a541f738b22380eb6 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/database/gitlab_schema_spec.rb82
-rw-r--r--spec/lib/gitlab/database/no_cross_db_foreign_keys_spec.rb6
-rw-r--r--spec/models/application_setting_spec.rb38
-rw-r--r--spec/models/container_expiration_policy_spec.rb3
-rw-r--r--spec/models/dependency_proxy/image_ttl_group_policy_spec.rb3
-rw-r--r--spec/models/integrations/apple_app_store_spec.rb3
-rw-r--r--spec/models/integrations/google_play_spec.rb3
-rw-r--r--spec/models/issue_spec.rb3
-rw-r--r--spec/models/namespace/package_setting_spec.rb10
-rw-r--r--spec/models/project_setting_spec.rb3
-rw-r--r--spec/models/user_preference_spec.rb3
-rw-r--r--spec/requests/api/groups_spec.rb14
-rw-r--r--spec/support/database/prevent_cross_joins.rb2
13 files changed, 91 insertions, 82 deletions
diff --git a/spec/lib/gitlab/database/gitlab_schema_spec.rb b/spec/lib/gitlab/database/gitlab_schema_spec.rb
index e402014df90..a6de695c345 100644
--- a/spec/lib/gitlab/database/gitlab_schema_spec.rb
+++ b/spec/lib/gitlab/database/gitlab_schema_spec.rb
@@ -226,57 +226,83 @@ RSpec.describe Gitlab::Database::GitlabSchema, feature_category: :database do
allow_cross_joins: %i[gitlab_shared],
allow_cross_transactions: %i[gitlab_internal gitlab_shared],
allow_cross_foreign_keys: %i[]
+ ),
+ Gitlab::Database::GitlabSchemaInfo.new(
+ name: "gitlab_main_cell",
+ allow_cross_joins: [
+ :gitlab_shared,
+ :gitlab_main,
+ { gitlab_main_clusterwide: { specific_tables: %w[plans] } }
+ ],
+ allow_cross_transactions: [
+ :gitlab_internal,
+ :gitlab_shared,
+ :gitlab_main,
+ { gitlab_main_clusterwide: { specific_tables: %w[plans] } }
+ ],
+ allow_cross_foreign_keys: [
+ { gitlab_main_clusterwide: { specific_tables: %w[plans] } }
+ ]
)
].index_by(&:name)
)
end
describe '.cross_joins_allowed?' do
- where(:schemas, :result) do
- %i[] | true
- %i[gitlab_main_clusterwide gitlab_main] | true
- %i[gitlab_main_clusterwide gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_main gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_internal] | false
- %i[gitlab_main gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_main gitlab_shared] | true
- %i[gitlab_main_clusterwide gitlab_shared] | true
+ where(:schemas, :tables, :result) do
+ %i[] | %i[] | true
+ %i[gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_main gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_internal] | %i[] | false
+ %i[gitlab_main gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_main gitlab_shared] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_shared] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[users namespaces] | false
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[plans namespaces] | true
end
with_them do
- it { expect(described_class.cross_joins_allowed?(schemas)).to eq(result) }
+ it { expect(described_class.cross_joins_allowed?(schemas, tables)).to eq(result) }
end
end
describe '.cross_transactions_allowed?' do
- where(:schemas, :result) do
- %i[] | true
- %i[gitlab_main_clusterwide gitlab_main] | true
- %i[gitlab_main_clusterwide gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_main gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_internal] | true
- %i[gitlab_main gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_main gitlab_shared] | true
- %i[gitlab_main_clusterwide gitlab_shared] | true
+ where(:schemas, :tables, :result) do
+ %i[] | %i[] | true
+ %i[gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_main gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_internal] | %i[] | true
+ %i[gitlab_main gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_main gitlab_shared] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_shared] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[users namespaces] | false
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[plans namespaces] | true
end
with_them do
- it { expect(described_class.cross_transactions_allowed?(schemas)).to eq(result) }
+ it { expect(described_class.cross_transactions_allowed?(schemas, tables)).to eq(result) }
end
end
describe '.cross_foreign_key_allowed?' do
- where(:schemas, :result) do
- %i[] | false
- %i[gitlab_main_clusterwide gitlab_main] | true
- %i[gitlab_main_clusterwide gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_internal] | false
- %i[gitlab_main gitlab_ci] | false
- %i[gitlab_main_clusterwide gitlab_shared] | false
+ where(:schemas, :tables, :result) do
+ %i[] | %i[] | false
+ %i[gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_main] | %i[] | true
+ %i[gitlab_main_clusterwide gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_internal] | %i[] | false
+ %i[gitlab_main gitlab_ci] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_shared] | %i[] | false
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[users namespaces] | false
+ %i[gitlab_main_clusterwide gitlab_main_cell] | %w[plans namespaces] | true
end
with_them do
- it { expect(described_class.cross_foreign_key_allowed?(schemas)).to eq(result) }
+ it { expect(described_class.cross_foreign_key_allowed?(schemas, tables)).to eq(result) }
end
end
end
diff --git a/spec/lib/gitlab/database/no_cross_db_foreign_keys_spec.rb b/spec/lib/gitlab/database/no_cross_db_foreign_keys_spec.rb
index 2fa4c9e562f..b807f6cd784 100644
--- a/spec/lib/gitlab/database/no_cross_db_foreign_keys_spec.rb
+++ b/spec/lib/gitlab/database/no_cross_db_foreign_keys_spec.rb
@@ -34,9 +34,11 @@ RSpec.describe 'cross-database foreign keys' do
end
def is_cross_db?(fk_record)
- table_schemas = Gitlab::Database::GitlabSchema.table_schemas!([fk_record.from_table, fk_record.to_table])
+ tables = [fk_record.from_table, fk_record.to_table]
- !Gitlab::Database::GitlabSchema.cross_foreign_key_allowed?(table_schemas)
+ table_schemas = Gitlab::Database::GitlabSchema.table_schemas!(tables)
+
+ !Gitlab::Database::GitlabSchema.cross_foreign_key_allowed?(table_schemas, tables)
end
it 'onlies have allowed list of cross-database foreign keys', :aggregate_failures do
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 3fc7d8f6fc8..ac07755e29c 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -69,8 +69,7 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to allow_value("dev.gitlab.com").for(:commit_email_hostname) }
it { is_expected.not_to allow_value("@dev.gitlab").for(:commit_email_hostname) }
- it { is_expected.to allow_value(true, false).for(:container_expiration_policies_enable_historic_entries) }
- it { is_expected.not_to allow_value(nil).for(:container_expiration_policies_enable_historic_entries) }
+ it { is_expected.to validate_inclusion_of(:container_expiration_policies_enable_historic_entries).in_array([true, false]) }
it { is_expected.to allow_value("myemail@gitlab.com").for(:lets_encrypt_notification_email) }
it { is_expected.to allow_value(nil).for(:lets_encrypt_notification_email) }
@@ -113,7 +112,7 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to validate_numericality_of(:container_registry_cleanup_tags_service_max_list_size).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:container_registry_data_repair_detail_worker_max_concurrency).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:container_registry_expiration_policies_worker_capacity).only_integer.is_greater_than_or_equal_to(0) }
- it { is_expected.to allow_value(true, false).for(:container_registry_expiration_policies_caching) }
+ it { is_expected.to validate_inclusion_of(:container_registry_expiration_policies_caching).in_array([true, false]) }
it { is_expected.to validate_numericality_of(:container_registry_import_max_tags_count).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:container_registry_import_max_retries).only_integer.is_greater_than_or_equal_to(0) }
@@ -149,8 +148,7 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to validate_numericality_of(:snippet_size_limit).only_integer.is_greater_than(0) }
it { is_expected.to validate_numericality_of(:wiki_page_max_content_bytes).only_integer.is_greater_than_or_equal_to(1024) }
- it { is_expected.to allow_value(true, false).for(:wiki_asciidoc_allow_uri_includes) }
- it { is_expected.not_to allow_value(nil).for(:wiki_asciidoc_allow_uri_includes) }
+ it { is_expected.to validate_inclusion_of(:wiki_asciidoc_allow_uri_includes).in_array([true, false]) }
it { is_expected.to validate_presence_of(:max_artifacts_size) }
it { is_expected.to validate_numericality_of(:max_artifacts_size).only_integer.is_greater_than(0) }
it { is_expected.to validate_presence_of(:max_yaml_size_bytes) }
@@ -162,11 +160,9 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to validate_presence_of(:max_terraform_state_size_bytes) }
it { is_expected.to validate_numericality_of(:max_terraform_state_size_bytes).only_integer.is_greater_than_or_equal_to(0) }
- it { is_expected.to allow_value(true, false).for(:user_defaults_to_private_profile) }
- it { is_expected.not_to allow_value(nil).for(:user_defaults_to_private_profile) }
+ it { is_expected.to validate_inclusion_of(:user_defaults_to_private_profile).in_array([true, false]) }
- it { is_expected.to allow_values([true, false]).for(:deny_all_requests_except_allowed) }
- it { is_expected.not_to allow_value(nil).for(:deny_all_requests_except_allowed) }
+ it { is_expected.to validate_inclusion_of(:deny_all_requests_except_allowed).in_array([true, false]) }
it 'ensures max_pages_size is an integer greater than 0 (or equal to 0 to indicate unlimited/maximum)' do
is_expected.to validate_numericality_of(:max_pages_size).only_integer.is_greater_than_or_equal_to(0)
@@ -254,8 +250,7 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to allow_value('http://example.com/').for(:public_runner_releases_url) }
it { is_expected.not_to allow_value(nil).for(:public_runner_releases_url) }
- it { is_expected.to allow_value([true, false]).for(:update_runner_versions_enabled) }
- it { is_expected.not_to allow_value(nil).for(:update_runner_versions_enabled) }
+ it { is_expected.to validate_inclusion_of(:update_runner_versions_enabled).in_array([true, false]) }
it { is_expected.not_to allow_value(['']).for(:valid_runner_registrars) }
it { is_expected.not_to allow_value(['OBVIOUSLY_WRONG']).for(:valid_runner_registrars) }
@@ -268,21 +263,17 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.to allow_value(http).for(:jira_connect_proxy_url) }
it { is_expected.to allow_value(https).for(:jira_connect_proxy_url) }
- it { is_expected.to allow_value(true, false).for(:bulk_import_enabled) }
- it { is_expected.not_to allow_value(nil).for(:bulk_import_enabled) }
+ it { is_expected.to validate_inclusion_of(:bulk_import_enabled).in_array([true, false]) }
- it { is_expected.to allow_value(true, false).for(:allow_runner_registration_token) }
- it { is_expected.not_to allow_value(nil).for(:allow_runner_registration_token) }
+ it { is_expected.to validate_inclusion_of(:allow_runner_registration_token).in_array([true, false]) }
- it { is_expected.to allow_value(true, false).for(:gitlab_dedicated_instance) }
- it { is_expected.not_to allow_value(nil).for(:gitlab_dedicated_instance) }
+ it { is_expected.to validate_inclusion_of(:gitlab_dedicated_instance).in_array([true, false]) }
it { is_expected.not_to allow_value(apdex_slo: '10').for(:prometheus_alert_db_indicators_settings) }
it { is_expected.to allow_value(nil).for(:prometheus_alert_db_indicators_settings) }
it { is_expected.to allow_value(valid_prometheus_alert_db_indicators_settings).for(:prometheus_alert_db_indicators_settings) }
- it { is_expected.to allow_value([true, false]).for(:silent_mode_enabled) }
- it { is_expected.not_to allow_value(nil).for(:silent_mode_enabled) }
+ it { is_expected.to validate_inclusion_of(:silent_mode_enabled).in_array([true, false]) }
it { is_expected.to allow_value(0).for(:ci_max_includes) }
it { is_expected.to allow_value(200).for(:ci_max_includes) }
@@ -298,16 +289,13 @@ RSpec.describe ApplicationSetting, feature_category: :shared, type: :model do
it { is_expected.not_to allow_value(10.5).for(:ci_max_total_yaml_size_bytes) }
it { is_expected.not_to allow_value(-1).for(:ci_max_total_yaml_size_bytes) }
- it { is_expected.to allow_value([true, false]).for(:remember_me_enabled) }
- it { is_expected.not_to allow_value(nil).for(:remember_me_enabled) }
+ it { is_expected.to validate_inclusion_of(:remember_me_enabled).in_array([true, false]) }
it { is_expected.to validate_numericality_of(:namespace_aggregation_schedule_lease_duration_in_seconds).only_integer.is_greater_than(0) }
- it { is_expected.to allow_values([true, false]).for(:instance_level_code_suggestions_enabled) }
- it { is_expected.not_to allow_value(nil).for(:instance_level_code_suggestions_enabled) }
+ it { is_expected.to validate_inclusion_of(:instance_level_code_suggestions_enabled).in_array([true, false]) }
- it { is_expected.to allow_values([true, false]).for(:package_registry_allow_anyone_to_pull_option) }
- it { is_expected.not_to allow_value(nil).for(:package_registry_allow_anyone_to_pull_option) }
+ it { is_expected.to validate_inclusion_of(:package_registry_allow_anyone_to_pull_option).in_array([true, false]) }
context 'when deactivate_dormant_users is enabled' do
before do
diff --git a/spec/models/container_expiration_policy_spec.rb b/spec/models/container_expiration_policy_spec.rb
index e5f9fdd410e..1e911af5670 100644
--- a/spec/models/container_expiration_policy_spec.rb
+++ b/spec/models/container_expiration_policy_spec.rb
@@ -11,8 +11,7 @@ RSpec.describe ContainerExpirationPolicy, type: :model do
it { is_expected.to validate_presence_of(:project) }
describe '#enabled' do
- it { is_expected.to allow_value(true, false).for(:enabled) }
- it { is_expected.not_to allow_value(nil).for(:enabled) }
+ it { is_expected.to validate_inclusion_of(:enabled).in_array([true, false]) }
end
describe '#cadence' do
diff --git a/spec/models/dependency_proxy/image_ttl_group_policy_spec.rb b/spec/models/dependency_proxy/image_ttl_group_policy_spec.rb
index a58e8df45e4..203f477c1a0 100644
--- a/spec/models/dependency_proxy/image_ttl_group_policy_spec.rb
+++ b/spec/models/dependency_proxy/image_ttl_group_policy_spec.rb
@@ -11,8 +11,7 @@ RSpec.describe DependencyProxy::ImageTtlGroupPolicy, type: :model do
it { is_expected.to validate_presence_of(:group) }
describe '#enabled' do
- it { is_expected.to allow_value(true, false).for(:enabled) }
- it { is_expected.not_to allow_value(nil).for(:enabled) }
+ it { is_expected.to validate_inclusion_of(:enabled).in_array([true, false]) }
end
describe '#ttl' do
diff --git a/spec/models/integrations/apple_app_store_spec.rb b/spec/models/integrations/apple_app_store_spec.rb
index 9864fe38d3f..ea66c382726 100644
--- a/spec/models/integrations/apple_app_store_spec.rb
+++ b/spec/models/integrations/apple_app_store_spec.rb
@@ -13,8 +13,7 @@ RSpec.describe Integrations::AppleAppStore, feature_category: :mobile_devops do
it { is_expected.to validate_presence_of :app_store_key_id }
it { is_expected.to validate_presence_of :app_store_private_key }
it { is_expected.to validate_presence_of :app_store_private_key_file_name }
- it { is_expected.to allow_value(true, false).for(:app_store_protected_refs) }
- it { is_expected.not_to allow_value(nil).for(:app_store_protected_refs) }
+ it { is_expected.to validate_inclusion_of(:app_store_protected_refs).in_array([true, false]) }
it { is_expected.to allow_value('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee').for(:app_store_issuer_id) }
it { is_expected.not_to allow_value('abcde').for(:app_store_issuer_id) }
it { is_expected.to allow_value(File.read('spec/fixtures/ssl_key.pem')).for(:app_store_private_key) }
diff --git a/spec/models/integrations/google_play_spec.rb b/spec/models/integrations/google_play_spec.rb
index a0bc73378d3..c5b0c058809 100644
--- a/spec/models/integrations/google_play_spec.rb
+++ b/spec/models/integrations/google_play_spec.rb
@@ -20,8 +20,7 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
it { is_expected.to allow_value('a.a.a').for(:package_name) }
it { is_expected.to allow_value('com.example').for(:package_name) }
it { is_expected.not_to allow_value('com').for(:package_name) }
- it { is_expected.to allow_value(true, false).for(:google_play_protected_refs) }
- it { is_expected.not_to allow_value(nil).for(:google_play_protected_refs) }
+ it { is_expected.to validate_inclusion_of(:google_play_protected_refs).in_array([true, false]) }
it { is_expected.not_to allow_value('com.example.my app').for(:package_name) }
it { is_expected.not_to allow_value('1com.example.myapp').for(:package_name) }
it { is_expected.not_to allow_value('com.1example.myapp').for(:package_name) }
diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb
index f240670c514..1b10a3048c7 100644
--- a/spec/models/issue_spec.rb
+++ b/spec/models/issue_spec.rb
@@ -69,8 +69,7 @@ RSpec.describe Issue, feature_category: :team_planning do
end
describe 'validations' do
- it { is_expected.not_to allow_value(nil).for(:confidential) }
- it { is_expected.to allow_value(true, false).for(:confidential) }
+ it { is_expected.to validate_inclusion_of(:confidential).in_array([true, false]) }
end
describe 'custom validations' do
diff --git a/spec/models/namespace/package_setting_spec.rb b/spec/models/namespace/package_setting_spec.rb
index f3fda200fda..e6096bc9267 100644
--- a/spec/models/namespace/package_setting_spec.rb
+++ b/spec/models/namespace/package_setting_spec.rb
@@ -11,13 +11,9 @@ RSpec.describe Namespace::PackageSetting, feature_category: :package_registry do
it { is_expected.to validate_presence_of(:namespace) }
describe '#maven_duplicates_allowed' do
- it { is_expected.to allow_value(true, false).for(:maven_duplicates_allowed) }
- it { is_expected.not_to allow_value(nil).for(:maven_duplicates_allowed) }
- it { is_expected.to allow_value(true, false).for(:generic_duplicates_allowed) }
- it { is_expected.not_to allow_value(nil).for(:generic_duplicates_allowed) }
- it { is_expected.to allow_value(true).for(:nuget_duplicates_allowed) }
- it { is_expected.to allow_value(false).for(:nuget_duplicates_allowed) }
- it { is_expected.not_to allow_value(nil).for(:nuget_duplicates_allowed) }
+ it { is_expected.to validate_inclusion_of(:maven_duplicates_allowed).in_array([true, false]) }
+ it { is_expected.to validate_inclusion_of(:generic_duplicates_allowed).in_array([true, false]) }
+ it { is_expected.to validate_inclusion_of(:nuget_duplicates_allowed).in_array([true, false]) }
end
describe 'regex values' do
diff --git a/spec/models/project_setting_spec.rb b/spec/models/project_setting_spec.rb
index 3b890e75064..719e51018ac 100644
--- a/spec/models/project_setting_spec.rb
+++ b/spec/models/project_setting_spec.rb
@@ -26,8 +26,7 @@ RSpec.describe ProjectSetting, type: :model, feature_category: :groups_and_proje
it { is_expected.to allow_value([]).for(:target_platforms) }
it { is_expected.to validate_length_of(:issue_branch_template).is_at_most(255) }
- it { is_expected.not_to allow_value(nil).for(:suggested_reviewers_enabled) }
- it { is_expected.to allow_value(true, false).for(:suggested_reviewers_enabled) }
+ it { is_expected.to validate_inclusion_of(:suggested_reviewers_enabled).in_array([true, false]) }
it 'allows any combination of the allowed target platforms' do
valid_target_platform_combinations.each do |target_platforms|
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index 401a85e2f82..343576de4d3 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -49,8 +49,7 @@ RSpec.describe UserPreference, feature_category: :user_profile do
end
describe 'pass_user_identities_to_ci_jwt' do
- it { is_expected.to allow_value(true, false).for(:pass_user_identities_to_ci_jwt) }
- it { is_expected.not_to allow_value(nil).for(:pass_user_identities_to_ci_jwt) }
+ it { is_expected.to validate_inclusion_of(:pass_user_identities_to_ci_jwt).in_array([true, false]) }
it { is_expected.not_to allow_value("").for(:pass_user_identities_to_ci_jwt) }
end
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index 7b1da1c691d..662e11f7cfb 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -1249,19 +1249,23 @@ RSpec.describe API::Groups, feature_category: :groups_and_projects do
expect(json_response.length).to eq(6)
end
- it 'avoids N+1 queries', :aggregate_failures, :use_sql_query_cache, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/383788' do
- get api("/groups/#{group1.id}/projects", user1), params: { include_subgroups: true }
- expect(respone).to have_gitlab_http_status(:ok)
+ it 'avoids N+1 queries', :aggregate_failures do
+ get api("/groups/#{group1.id}/projects", user1), params: { include_subgroups: true } # warm-up
+
+ expect(response).to have_gitlab_http_status(:ok)
control = ActiveRecord::QueryRecorder.new(skip_cached: false) do
get api("/groups/#{group1.id}/projects", user1), params: { include_subgroups: true }
end
- create_list(:project, 2, :public, namespace: group1)
+ create(:project, :public, namespace: group1)
+ # threshold number 2 is the additional number of queries which are getting executed.
+ # with this we are allowing some N+1 that may already exist but is not obvious.
+ # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132246#note_1581106553
expect do
get api("/groups/#{group1.id}/projects", user1), params: { include_subgroups: true }
- end.not_to exceed_all_query_limit(control.count)
+ end.to issue_same_number_of_queries_as(control).with_threshold(2)
end
end
diff --git a/spec/support/database/prevent_cross_joins.rb b/spec/support/database/prevent_cross_joins.rb
index 443216ba9df..3ff83e685ba 100644
--- a/spec/support/database/prevent_cross_joins.rb
+++ b/spec/support/database/prevent_cross_joins.rb
@@ -41,7 +41,7 @@ module Database
schemas = ::Gitlab::Database::GitlabSchema.table_schemas!(tables)
- unless ::Gitlab::Database::GitlabSchema.cross_joins_allowed?(schemas)
+ unless ::Gitlab::Database::GitlabSchema.cross_joins_allowed?(schemas, tables)
Thread.current[:has_cross_join_exception] = true
raise CrossJoinAcrossUnsupportedTablesError,
"Unsupported cross-join across '#{tables.join(", ")}' querying '#{schemas.to_a.join(", ")}' discovered " \