diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /spec/support/shared_examples/models/wiki_shared_examples.rb | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'spec/support/shared_examples/models/wiki_shared_examples.rb')
-rw-r--r-- | spec/support/shared_examples/models/wiki_shared_examples.rb | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/wiki_shared_examples.rb b/spec/support/shared_examples/models/wiki_shared_examples.rb index 2498bf35a09..bc5956e3eec 100644 --- a/spec/support/shared_examples/models/wiki_shared_examples.rb +++ b/spec/support/shared_examples/models/wiki_shared_examples.rb @@ -2,6 +2,7 @@ RSpec.shared_examples 'wiki model' do let_it_be(:user) { create(:user, :commit_email) } + let(:wiki_container) { raise NotImplementedError } let(:wiki_container_without_repo) { raise NotImplementedError } let(:wiki_lfs_enabled) { false } @@ -536,4 +537,98 @@ RSpec.shared_examples 'wiki model' do expect(subject.hook_attrs.keys).to contain_exactly(:web_url, :git_ssh_url, :git_http_url, :path_with_namespace, :default_branch) end end + + describe '#default_branch' do + subject { wiki.default_branch } + + before do + allow(Gitlab::DefaultBranch).to receive(:value).and_return('main') + end + + context 'when repository is not created' do + let(:wiki_container) { wiki_container_without_repo } + + it 'returns the instance default branch' do + expect(subject).to eq 'main' + end + end + + context 'when repository is empty' do + let(:wiki_container) { wiki_container_without_repo } + + before do + wiki.repository.create_if_not_exists + end + + it 'returns the instance default branch' do + expect(subject).to eq 'main' + end + end + + context 'when repository is not empty' do + it 'returns the repository default branch' do + wiki.create_page('index', 'test content') + + expect(subject).to eq wiki.repository.root_ref + end + end + end + + describe '#create_wiki_repository' do + let(:head_path) { Rails.root.join(TestEnv.repos_path, "#{wiki.disk_path}.git", 'HEAD') } + let(:default_branch) { 'foo' } + + before do + allow(Gitlab::CurrentSettings).to receive(:default_branch_name).and_return(default_branch) + end + + subject { wiki.create_wiki_repository } + + context 'when repository is not created' do + let(:wiki_container) { wiki_container_without_repo } + + it 'changes the HEAD reference to the default branch' do + expect(wiki.empty?).to eq true + + subject + + expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}" + end + end + + context 'when repository is empty' do + let(:wiki_container) { wiki_container_without_repo } + + it 'changes the HEAD reference to the default branch' do + wiki.repository.create_if_not_exists + wiki.repository.raw_repository.write_ref('HEAD', 'refs/heads/bar') + + subject + + expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}" + end + end + + context 'when repository is not empty' do + before do + wiki.create_page('index', 'test content') + end + + it 'does nothing when HEAD points to the right branch' do + expect(wiki.repository.raw_repository).not_to receive(:write_ref) + + subject + end + + context 'when HEAD points to the wrong branch' do + it 'rewrites HEAD with the right branch' do + wiki.repository.raw_repository.write_ref('HEAD', 'refs/heads/bar') + + subject + + expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}" + end + end + end + end end |