diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-17 14:33:21 +0300 |
commit | 7021455bd1ed7b125c55eb1b33c5a01f2bc55ee0 (patch) | |
tree | 5bdc2229f5198d516781f8d24eace62fc7e589e9 /spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb | |
parent | 185b095e93520f96e9cfc31d9c3e69b498cdab7c (diff) |
Add latest changes from gitlab-org/gitlab@15-6-stable-eev15.6.0-rc42
Diffstat (limited to 'spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb')
-rw-r--r-- | spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb | 58 |
1 files changed, 41 insertions, 17 deletions
diff --git a/spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb b/spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb index 7411bc95147..1cfeeac49cd 100644 --- a/spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb +++ b/spec/models/preloaders/user_max_access_level_in_projects_preloader_spec.rb @@ -28,34 +28,58 @@ RSpec.describe Preloaders::UserMaxAccessLevelInProjectsPreloader do end end - describe '#execute', :request_store do + shared_examples '#execute' do let(:projects_arg) { projects } - before do - Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects_arg, user).execute - end - - it 'avoids N+1 queries' do - expect { query }.not_to make_queries - end - - context 'when projects is an array of IDs' do - let(:projects_arg) { projects.map(&:id) } + context 'when user is present' do + before do + Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects_arg, user).execute + end it 'avoids N+1 queries' do expect { query }.not_to make_queries end + + context 'when projects is an array of IDs' do + let(:projects_arg) { projects.map(&:id) } + + it 'avoids N+1 queries' do + expect { query }.not_to make_queries + end + end + + # Test for handling of SQL table name clashes. + context 'when projects is a relation including project_authorizations' do + let(:projects_arg) do + Project.where(id: ProjectAuthorization.where(project_id: projects).select(:project_id)) + end + + it 'avoids N+1 queries' do + expect { query }.not_to make_queries + end + end end - # Test for handling of SQL table name clashes. - context 'when projects is a relation including project_authorizations' do - let(:projects_arg) do - Project.where(id: ProjectAuthorization.where(project_id: projects).select(:project_id)) + context 'when user is not present' do + before do + Preloaders::UserMaxAccessLevelInProjectsPreloader.new(projects_arg, nil).execute end - it 'avoids N+1 queries' do - expect { query }.not_to make_queries + it 'does not avoid N+1 queries' do + expect { query }.to make_queries + end + end + end + + describe '#execute', :request_store do + include_examples '#execute' + + context 'when projects_preloader_fix is disabled' do + before do + stub_feature_flags(projects_preloader_fix: false) end + + include_examples '#execute' end end end |