pool_repository_spec.rb 1.33 KB
Newer Older
1 2
# frozen_string_literal: true

3 4 5 6 7
require 'spec_helper'

describe PoolRepository do
  describe 'associations' do
    it { is_expected.to belong_to(:shard) }
8
    it { is_expected.to have_one(:source_project) }
9 10 11 12 13 14 15
    it { is_expected.to have_many(:member_projects) }
  end

  describe 'validations' do
    let!(:pool_repository) { create(:pool_repository) }

    it { is_expected.to validate_presence_of(:shard) }
16
    it { is_expected.to validate_presence_of(:source_project) }
17 18 19 20 21 22
  end

  describe '#disk_path' do
    it 'sets the hashed disk_path' do
      pool = create(:pool_repository)

23
      expect(pool.disk_path).to match(%r{\A@pools/\h{2}/\h{2}/\h{64}})
24 25
    end
  end
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

  describe '#unlink_repository' do
    let(:pool) { create(:pool_repository, :ready) }

    context 'when the last member leaves' do
      it 'schedules pool removal' do
        expect(::ObjectPool::DestroyWorker).to receive(:perform_async).with(pool.id).and_call_original

        pool.unlink_repository(pool.source_project.repository)
      end
    end

    context 'when the second member leaves' do
      it 'does not schedule pool removal' do
        create(:project, :repository, pool_repository: pool)
        expect(::ObjectPool::DestroyWorker).not_to receive(:perform_async).with(pool.id)

        pool.unlink_repository(pool.source_project.repository)
      end
    end
  end
47
end