debian-mirror-gitlab/spec/models/pool_repository_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe PoolRepository do
2019-02-15 15:39:39 +05:30
describe 'associations' do
it { is_expected.to belong_to(:shard) }
2019-07-31 22:56:46 +05:30
it { is_expected.to belong_to(:source_project) }
2019-02-15 15:39:39 +05:30
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) }
it { is_expected.to validate_presence_of(:source_project) }
end
describe '#disk_path' do
it 'sets the hashed disk_path' do
pool = create(:pool_repository)
expect(pool.disk_path).to match(%r{\A@pools/\h{2}/\h{2}/\h{64}})
end
end
2022-07-16 23:28:13 +05:30
describe '#unlink_repository' do
2019-02-15 15:39:39 +05:30
let(:pool) { create(:pool_repository, :ready) }
2022-07-16 23:28:13 +05:30
before do
pool.link_repository(pool.source_project.repository)
end
2019-02-15 15:39:39 +05:30
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
2022-11-25 23:54:43 +05:30
expect(pool.source_project.repository).to receive(:disconnect_alternates).and_call_original
2019-02-15 15:39:39 +05:30
2022-07-16 23:28:13 +05:30
pool.unlink_repository(pool.source_project.repository)
2019-02-15 15:39:39 +05:30
end
end
2022-10-11 01:57:18 +05:30
context 'when skipping disconnect' do
it 'does not change the alternates file' do
2022-11-25 23:54:43 +05:30
expect(pool.source_project.repository).not_to receive(:disconnect_alternates)
2022-10-11 01:57:18 +05:30
2022-11-25 23:54:43 +05:30
pool.unlink_repository(pool.source_project.repository, disconnect: false)
2022-10-11 01:57:18 +05:30
end
end
2019-02-15 15:39:39 +05:30
context 'when the second member leaves' do
it 'does not schedule pool removal' do
2022-07-16 23:28:13 +05:30
other_project = create(:project, :repository, pool_repository: pool)
pool.link_repository(other_project.repository)
2019-02-15 15:39:39 +05:30
expect(::ObjectPool::DestroyWorker).not_to receive(:perform_async).with(pool.id)
2022-11-25 23:54:43 +05:30
expect(pool.source_project.repository).to receive(:disconnect_alternates).and_call_original
2019-02-15 15:39:39 +05:30
2022-07-16 23:28:13 +05:30
pool.unlink_repository(pool.source_project.repository)
2019-02-15 15:39:39 +05:30
end
end
end
end