Unverified Commit a0222cf8 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre
Browse files

Track storage location for legacy storage projects

parent a9049532
......@@ -1244,10 +1244,8 @@ def check_repository_path_availability
end
def track_project_repository
return unless hashed_storage?(:repository)
project_repo = project_repository || build_project_repository
project_repo.update!(shard_name: repository_storage, disk_path: disk_path)
repository = project_repository || build_project_repository
repository.update!(shard_name: repository_storage, disk_path: disk_path)
end
def create_repository(force: false)
......
......@@ -1651,26 +1651,54 @@ def create_pipeline
end
describe '#track_project_repository' do
let(:project) { create(:project, :repository) }
shared_examples 'tracks storage location' do
context 'when a project repository entry does not exist' do
it 'creates a new entry' do
expect { project.track_project_repository }.to change(project, :project_repository)
end
it 'tracks the project storage location' do
project.track_project_repository
it 'creates a project_repository' do
project.track_project_repository
expect(project.project_repository).to have_attributes(
disk_path: project.disk_path,
shard_name: project.repository_storage
)
end
end
context 'when a tracking entry exists' do
let!(:project_repository) { create(:project_repository, project: project) }
let!(:shard) { create(:shard, name: 'foo') }
it 'does not create a new entry in the database' do
expect { project.track_project_repository }.not_to change(project, :project_repository)
end
expect(project.reload.project_repository).to be_present
expect(project.project_repository.disk_path).to eq(project.disk_path)
expect(project.project_repository.shard_name).to eq(project.repository_storage)
it 'updates the project storage location' do
allow(project).to receive(:disk_path).and_return('fancy/new/path')
allow(project).to receive(:repository_storage).and_return('foo')
project.track_project_repository
expect(project.project_repository).to have_attributes(
disk_path: 'fancy/new/path',
shard_name: 'foo'
)
end
end
end
it 'updates the project_repository' do
project.track_project_repository
context 'with projects on legacy storage' do
let(:project) { create(:project, :repository, :legacy_storage) }
allow(project).to receive(:disk_path).and_return('@fancy/new/path')
it_behaves_like 'tracks storage location'
end
expect do
project.track_project_repository
end.not_to change(ProjectRepository, :count)
context 'with projects on hashed storage' do
let(:project) { create(:project, :repository) }
expect(project.reload.project_repository.disk_path).to eq(project.disk_path)
it_behaves_like 'tracks storage location'
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment