diff options
author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-02 16:01:06 +0100 |
---|---|---|
committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-02 18:23:03 +0100 |
commit | 39011be53daee921dac1648044d1e68b9706197c (patch) | |
tree | 695cbcfa7346f2d4f8a4c566bd6f0ae31dd4f5c5 /spec/models | |
parent | 0a3fc7e3c283c10ef8415a719e83e80f0122af7d (diff) | |
download | gitlab-ce-39011be53daee921dac1648044d1e68b9706197c.tar.gz |
Extract method User#authorizations_for_projects.42877-fix-visibility-change-performance
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/user_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 3531de244bd..00b5226d874 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1635,6 +1635,32 @@ describe User do end end + describe '#authorizations_for_projects' do + let!(:user) { create(:user) } + subject { Project.where("EXISTS (?)", user.authorizations_for_projects) } + + it 'includes projects that belong to a user, but no other projects' do + owned = create(:project, :private, namespace: user.namespace) + member = create(:project, :private).tap { |p| p.add_master(user) } + other = create(:project) + + expect(subject).to include(owned) + expect(subject).to include(member) + expect(subject).not_to include(other) + end + + it 'includes projects a user has access to, but no other projects' do + other_user = create(:user) + accessible = create(:project, :private, namespace: other_user.namespace) do |project| + project.add_developer(user) + end + other = create(:project) + + expect(subject).to include(accessible) + expect(subject).not_to include(other) + end + end + describe '#authorized_projects', :delete do context 'with a minimum access level' do it 'includes projects for which the user is an owner' do |