diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-12-28 14:55:44 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-12-28 14:55:44 +0000 |
commit | 0d930161525032b7289d480d3ee6924e3ef10e6f (patch) | |
tree | 58fb377b7ce523745ceb11936dd053ce701b7925 /spec | |
parent | ce3cf6985cda53d618cdb5b7a86b625a72b4f8d6 (diff) | |
parent | f0ba001877e074eb8046f476c9972a47fe108f1b (diff) | |
download | gitlab-ce-0d930161525032b7289d480d3ee6924e3ef10e6f.tar.gz |
Merge branch '26126-cache-even-when-no-projects' into 'master'
Cache project authorizations even when user has access to zero projects
Closes #26126
See merge request !8327
Diffstat (limited to 'spec')
-rw-r--r-- | spec/services/users/refresh_authorized_projects_service_spec.rb | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/spec/services/users/refresh_authorized_projects_service_spec.rb b/spec/services/users/refresh_authorized_projects_service_spec.rb index 72c8f7cd8ec..1f6919151de 100644 --- a/spec/services/users/refresh_authorized_projects_service_spec.rb +++ b/spec/services/users/refresh_authorized_projects_service_spec.rb @@ -54,12 +54,37 @@ describe Users::RefreshAuthorizedProjectsService do end describe '#update_authorizations' do - it 'does nothing when there are no rows to add and remove' do - expect(user).not_to receive(:remove_project_authorizations) - expect(ProjectAuthorization).not_to receive(:insert_authorizations) - expect(user).not_to receive(:set_authorized_projects_column) + context 'when there are no rows to add and remove' do + it 'does not change authorizations' do + expect(user).not_to receive(:remove_project_authorizations) + expect(ProjectAuthorization).not_to receive(:insert_authorizations) - service.update_authorizations([], []) + service.update_authorizations([], []) + end + + context 'when the authorized projects column is not set' do + before do + user.update!(authorized_projects_populated: nil) + end + + it 'populates the authorized projects column' do + service.update_authorizations([], []) + + expect(user.authorized_projects_populated).to eq true + end + end + + context 'when the authorized projects column is set' do + before do + user.update!(authorized_projects_populated: true) + end + + it 'does nothing' do + expect(user).not_to receive(:set_authorized_projects_column) + + service.update_authorizations([], []) + end + end end it 'removes authorizations that should be removed' do @@ -84,7 +109,7 @@ describe Users::RefreshAuthorizedProjectsService do it 'populates the authorized projects column' do # make sure we start with a nil value no matter what the default in the # factory may be. - user.update(authorized_projects_populated: nil) + user.update!(authorized_projects_populated: nil) service.update_authorizations([], [[user.id, project.id, Gitlab::Access::MASTER]]) |