diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-18 12:21:06 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-11-18 13:05:45 +0100 |
commit | fbcf3bd3fc94a39982e2bb11aa61ac014326e53a (patch) | |
tree | 3c5106989bfbc085f665c4c87433e592085c049d /spec/finders/personal_projects_finder_spec.rb | |
parent | 2110247f83440f4a1044b999ff0f2630bd36e969 (diff) | |
download | gitlab-ce-fbcf3bd3fc94a39982e2bb11aa61ac014326e53a.tar.gz |
Refactor ProjectsFinder to not pluck IDs
This class now uses a UNION (when needed) instead of plucking tens of
thousands of project IDs into memory. The tests have also been
re-written to ensure all different use cases are tested properly
(assuming I didn't forget any cases).
The finder has also been broken up into 3 different finder classes:
* ContributedProjectsFinder: class for getting the projects a user
contributed to.
* PersonalProjectsFinder: class for getting the personal projects of a
user.
* ProjectsFinder: class for getting generic projects visible to a given
user.
Previously a lot of the logic of these finders was handled directly in
the users controller.
Diffstat (limited to 'spec/finders/personal_projects_finder_spec.rb')
-rw-r--r-- | spec/finders/personal_projects_finder_spec.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/finders/personal_projects_finder_spec.rb b/spec/finders/personal_projects_finder_spec.rb new file mode 100644 index 00000000000..6bd4e6a3f3a --- /dev/null +++ b/spec/finders/personal_projects_finder_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe PersonalProjectsFinder do + let(:source_user) { create(:user) } + let(:current_user) { create(:user) } + + let(:finder) { described_class.new(source_user) } + + let!(:public_project) do + create(:project, :public, namespace: source_user.namespace, name: 'A', + path: 'A') + end + + let!(:private_project) do + create(:project, :private, namespace: source_user.namespace, name: 'B', + path: 'B') + end + + before do + private_project.team << [current_user, Gitlab::Access::DEVELOPER] + end + + describe 'without a current user' do + subject { finder.execute } + + it { is_expected.to eq([public_project]) } + end + + describe 'with a current user' do + subject { finder.execute(current_user) } + + it { is_expected.to eq([private_project, public_project]) } + end +end |