personal_projects_finder_spec.rb 1.15 KB
Newer Older
1 2 3
require 'spec_helper'

describe PersonalProjectsFinder do
4 5 6
  let(:source_user)     { create(:user) }
  let(:current_user)    { create(:user) }
  let(:finder)          { described_class.new(source_user) }
7 8 9
  let!(:public_project) do
    create(:project, :public, namespace: source_user.namespace, updated_at: 1.hour.ago)
  end
10 11

  let!(:private_project) do
12
    create(:project, :private, namespace: source_user.namespace, updated_at: 3.hours.ago, path: 'mepmep')
13 14
  end

Felipe Artur's avatar
Felipe Artur committed
15
  let!(:internal_project) do
16
    create(:project, :internal, namespace: source_user.namespace, updated_at: 2.hours.ago, path: 'C')
Felipe Artur's avatar
Felipe Artur committed
17 18
  end

19
  before do
20
    private_project.add_developer(current_user)
21 22 23 24 25 26 27 28 29 30 31
  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) }

Felipe Artur's avatar
Felipe Artur committed
32
    context 'normal user' do
33
      it { is_expected.to eq([public_project, internal_project, private_project]) }
Felipe Artur's avatar
Felipe Artur committed
34 35 36
    end

    context 'external' do
37
      before do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
38
        current_user.update(external: true)
39
      end
Felipe Artur's avatar
Felipe Artur committed
40

41
      it { is_expected.to eq([public_project, private_project]) }
Felipe Artur's avatar
Felipe Artur committed
42
    end
43 44
  end
end