diff options
author | Mark Fletcher <mark@gitlab.com> | 2017-09-19 09:53:32 +0300 |
---|---|---|
committer | Mark Fletcher <mark@gitlab.com> | 2017-09-20 01:27:16 +0300 |
commit | 5f331ab7008ae6d5931873fb674daf9bc8aa06be (patch) | |
tree | 5420045e315920d79c8995a8d5b5f48a05b72524 | |
parent | ff594bb3a9e5fae72a286132b88e2f1ebd4549af (diff) |
Introduce ForkProjectsFinder class
* Will dry up the code to find projects between the ForksController and the API
-rw-r--r-- | app/finders/fork_projects_finder.rb | 6 | ||||
-rw-r--r-- | spec/finders/fork_projects_finder_spec.rb | 43 |
2 files changed, 49 insertions, 0 deletions
diff --git a/app/finders/fork_projects_finder.rb b/app/finders/fork_projects_finder.rb new file mode 100644 index 00000000000..28d1b31868e --- /dev/null +++ b/app/finders/fork_projects_finder.rb @@ -0,0 +1,6 @@ +class ForkProjectsFinder < ProjectsFinder + def initialize(project, params: {}, current_user: nil) + project_ids = project.forks.includes(:creator).select(:id) + super(params: params, current_user: current_user, project_ids_relation: project_ids) + end +end diff --git a/spec/finders/fork_projects_finder_spec.rb b/spec/finders/fork_projects_finder_spec.rb new file mode 100644 index 00000000000..f0cef7ea406 --- /dev/null +++ b/spec/finders/fork_projects_finder_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe ForkProjectsFinder do + let(:source_project) { create(:project, :empty_repo) } + let(:private_fork) { create(:project, :private, :empty_repo, name: 'A') } + let(:internal_fork) { create(:project, :internal, :empty_repo, name: 'B') } + let(:public_fork) { create(:project, :public, :empty_repo, name: 'C') } + + let(:non_member) { create(:user) } + let(:private_fork_member) { create(:user) } + + before do + private_fork.add_developer(private_fork_member) + + source_project.forks << private_fork + source_project.forks << internal_fork + source_project.forks << public_fork + end + + describe '#execute' do + let(:finder) { described_class.new(source_project, params: {}, current_user: current_user) } + + subject { finder.execute } + + describe 'without a user' do + let(:current_user) { nil } + + it { is_expected.to eq([public_fork]) } + end + + describe 'with a user' do + let(:current_user) { non_member } + + it { is_expected.to eq([public_fork, internal_fork]) } + end + + describe 'with a member' do + let(:current_user) { private_fork_member } + + it { is_expected.to eq([public_fork, internal_fork, private_fork]) } + end + end +end |