diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-15 15:19:25 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-06-19 19:11:35 +0200 |
commit | c9e277ee01b05da7e359459a0a25bdd9bc7dbca8 (patch) | |
tree | 4edc9db2155f8dff7f17bc769784d17f966e196c /spec/models | |
parent | 73bf9413b95d20860c09b3b37737c37add2d1342 (diff) | |
download | gitlab-ce-c9e277ee01b05da7e359459a0a25bdd9bc7dbca8.tar.gz |
Refactor GroupProjectsFinder#init_collection
This optimises how GroupProjectsFinder builds it collection, producing
simpler and faster queries in the process. It also cleans up the code a
bit to make it easier to understand.
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/project_spec.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 63333b7af1f..c7ba3ae903d 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -2060,4 +2060,36 @@ describe Project, models: true do expect(project.last_repository_updated_at.to_i).to eq(project.created_at.to_i) end end + + describe '.public_or_visible_to_user' do + let!(:user) { create(:user) } + + let!(:private_project) do + create(:empty_project, :private, creator: user, namespace: user.namespace) + end + + let!(:public_project) { create(:empty_project, :public) } + + context 'with a user' do + let(:projects) do + Project.all.public_or_visible_to_user(user) + end + + it 'includes projects the user has access to' do + expect(projects).to include(private_project) + end + + it 'includes projects the user can see' do + expect(projects).to include(public_project) + end + end + + context 'without a user' do + it 'only includes public projects' do + projects = Project.all.public_or_visible_to_user + + expect(projects).to eq([public_project]) + end + end + end end |