2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
RSpec.describe PersonalProjectsFinder do
|
2022-01-26 12:08:38 +05:30
|
|
|
let_it_be(:source_user) { create(:user) }
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
|
|
|
|
let(:finder) { described_class.new(source_user) }
|
2018-11-08 19:23:39 +05:30
|
|
|
let!(:public_project) do
|
2022-01-26 12:08:38 +05:30
|
|
|
create(:project, :public, namespace: source_user.namespace, updated_at: 1.hour.ago, path: 'pblc')
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
let!(:private_project_shared) do
|
2018-11-08 19:23:39 +05:30
|
|
|
create(:project, :private, namespace: source_user.namespace, updated_at: 3.hours.ago, path: 'mepmep')
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
let!(:internal_project) do
|
2018-11-08 19:23:39 +05:30
|
|
|
create(:project, :internal, namespace: source_user.namespace, updated_at: 2.hours.ago, path: 'C')
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
let!(:private_project_self) do
|
|
|
|
create(:project, :private, namespace: source_user.namespace, updated_at: 3.hours.ago, path: 'D')
|
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
before do
|
2022-01-26 12:08:38 +05:30
|
|
|
private_project_shared.add_developer(current_user)
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without a current user' do
|
|
|
|
subject { finder.execute }
|
|
|
|
|
|
|
|
it { is_expected.to eq([public_project]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with a current user' do
|
2016-06-02 11:05:42 +05:30
|
|
|
context 'normal user' do
|
2022-01-26 12:08:38 +05:30
|
|
|
subject { finder.execute(current_user) }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project, private_project_shared]) }
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'external' do
|
2022-01-26 12:08:38 +05:30
|
|
|
subject { finder.execute(current_user) }
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
before do
|
2020-10-24 23:57:45 +05:30
|
|
|
current_user.update!(external: true)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
it { is_expected.to match_array([public_project, private_project_shared]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and searching with an admin user', :enable_admin_mode do
|
|
|
|
subject { finder.execute(admin) }
|
|
|
|
|
|
|
|
it { is_expected.to match_array([public_project, internal_project, private_project_self, private_project_shared]) }
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
2015-11-26 14:37:03 +05:30
|
|
|
end
|
|
|
|
end
|