Commit 151965b1 authored by Markus Koller's avatar Markus Koller

Merge branch '299054-fj-refactor-some-group-wiki-methods' into 'master'

Split create_wiki_repository method

See merge request gitlab-org/gitlab!51923
parents 55a1e928 67a3fe27
...@@ -8,8 +8,12 @@ class GroupWiki < Wiki ...@@ -8,8 +8,12 @@ class GroupWiki < Wiki
def create_wiki_repository def create_wiki_repository
super super
track_wiki_repository(repository.shard)
end
def track_wiki_repository(shard)
storage_record = container.group_wiki_repository || container.build_group_wiki_repository storage_record = container.group_wiki_repository || container.build_group_wiki_repository
storage_record.update!(shard_name: repository.shard, disk_path: storage.disk_path) storage_record.update!(shard_name: shard, disk_path: storage.disk_path)
end end
override :storage override :storage
......
...@@ -12,46 +12,55 @@ RSpec.describe GroupWiki do ...@@ -12,46 +12,55 @@ RSpec.describe GroupWiki do
end end
describe '#create_wiki_repository' do describe '#create_wiki_repository' do
before do it 'tracks the repository storage in the database' do
shard = 'foo'
# Use a custom storage shard value, to make sure we're not falling back to the default. # Use a custom storage shard value, to make sure we're not falling back to the default.
allow(subject).to receive(:repository_storage).and_return('foo') allow(subject).to receive(:repository_storage).and_return(shard)
# Don't actually create the repository, because the storage shard doesn't exist. # Don't actually create the repository, because the storage shard doesn't exist.
allow(subject.repository).to receive(:create_if_not_exists) expect(subject.repository).to receive(:create_if_not_exists)
allow(subject).to receive(:repository_exists?).and_return(true) allow(subject).to receive(:repository_exists?).and_return(true)
expect(subject).to receive(:track_wiki_repository).with(shard)
subject.create_wiki_repository
end end
end
describe '#track_wiki_repository' do
let(:shard) { 'foo' }
context 'when a tracking entry does not exist' do context 'when a tracking entry does not exist' do
let(:wiki_container) { wiki_container_without_repo } let(:wiki_container) { wiki_container_without_repo }
it 'creates a new entry' do it 'creates a new entry' do
expect { subject.create_wiki_repository }.to change(wiki_container, :group_wiki_repository) expect { subject.track_wiki_repository(shard) }.to change(wiki_container, :group_wiki_repository)
.from(nil).to(kind_of(GroupWikiRepository)) .from(nil).to(kind_of(GroupWikiRepository))
end end
it 'tracks the storage location' do it 'tracks the storage location' do
subject.create_wiki_repository subject.track_wiki_repository(shard)
expect(wiki_container.group_wiki_repository).to have_attributes( expect(wiki_container.group_wiki_repository).to have_attributes(
disk_path: subject.storage.disk_path, disk_path: subject.storage.disk_path,
shard_name: 'foo' shard_name: shard
) )
end end
end end
context 'when a tracking entry exists' do context 'when a tracking entry exists' do
it 'does not create a new entry in the database' do it 'does not create a new entry in the database' do
expect { subject.create_wiki_repository }.not_to change(wiki_container, :group_wiki_repository) expect { subject.track_wiki_repository(shard) }.not_to change(wiki_container, :group_wiki_repository)
end end
it 'updates the storage location' do it 'updates the storage location' do
expect(subject.storage).to receive(:disk_path).and_return('fancy/new/path') expect(subject.storage).to receive(:disk_path).and_return('fancy/new/path')
subject.create_wiki_repository subject.track_wiki_repository(shard)
expect(wiki_container.group_wiki_repository).to have_attributes( expect(wiki_container.group_wiki_repository).to have_attributes(
disk_path: 'fancy/new/path', disk_path: 'fancy/new/path',
shard_name: 'foo' shard_name: shard
) )
end end
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