Commit 51da7c74 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Update tests for snippets to support default branch

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/331906
parent 2cf8a20b
......@@ -29,7 +29,7 @@ RSpec.describe Gitlab::ImportExport::SnippetRepoRestorer do
expect(restorer.restore).to be_truthy
end.to change { SnippetRepository.count }.by(1)
blob = snippet.repository.blob_at('HEAD', snippet.file_name)
blob = snippet.repository.blob_at(snippet.default_branch, snippet.file_name)
expect(blob).not_to be_nil
expect(blob.data).to eq(snippet.content)
end
......
......@@ -828,14 +828,10 @@ RSpec.describe Snippet do
end
context 'when default branch in settings is different from "master"' do
let(:default_branch) { 'main' }
let(:default_branch) { 'custom-branch' }
it 'changes the HEAD reference to the default branch' do
expect(File.read(head_path).squish).to eq 'ref: refs/heads/master'
subject
expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}"
expect { subject }.to change { File.read(head_path).squish }.to("ref: refs/heads/#{default_branch}")
end
end
end
......
......@@ -85,8 +85,8 @@ RSpec.describe 'Creating a Snippet' do
end.to change { Snippet.count }.by(1)
snippet = Snippet.last
created_file_1 = snippet.repository.blob_at('HEAD', file_1[:filePath])
created_file_2 = snippet.repository.blob_at('HEAD', file_2[:filePath])
created_file_1 = snippet.repository.blob_at(snippet.default_branch, file_1[:filePath])
created_file_2 = snippet.repository.blob_at(snippet.default_branch, file_2[:filePath])
expect(created_file_1.data).to match(file_1[:content])
expect(created_file_2.data).to match(file_2[:content])
......
......@@ -138,7 +138,7 @@ RSpec.describe API::ProjectSnippets do
aggregate_failures do
expect(snippet.repository.exists?).to be_truthy
blob = snippet.repository.blob_at('master', file_path)
blob = snippet.repository.blob_at(snippet.default_branch, file_path)
expect(blob.data).to eq file_content
end
......
......@@ -223,7 +223,7 @@ RSpec.describe API::Snippets, factory_default: :keep do
it 'commit the files to the repository' do
subject
blob = snippet.repository.blob_at('master', file_path)
blob = snippet.repository.blob_at(snippet.default_branch, file_path)
expect(blob.data).to eq file_content
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