Commit d69cea62 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Update tests for design to support default branch

Contributes to https://gitlab.com/gitlab-org/gitlab/-/issues/331906
parent 2cf8a20b
...@@ -119,7 +119,7 @@ module DesignManagement ...@@ -119,7 +119,7 @@ module DesignManagement
# Returns the latest blobs for the designs as a Hash of `{ Design => Blob }` # Returns the latest blobs for the designs as a Hash of `{ Design => Blob }`
def existing_blobs def existing_blobs
@existing_blobs ||= begin @existing_blobs ||= begin
items = designs.map { |d| ['HEAD', d.full_path] } items = designs.map { |d| [target_branch, d.full_path] }
repository.blobs_at(items).each_with_object({}) do |blob, h| repository.blobs_at(items).each_with_object({}) do |blob, h|
design = designs.find { |d| d.full_path == blob.path } design = designs.find { |d| d.full_path == blob.path }
......
...@@ -109,7 +109,7 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do ...@@ -109,7 +109,7 @@ RSpec.describe Projects::DesignManagement::Designs::RawImagesController do
context 'when sha is nil' do context 'when sha is nil' do
let(:sha) { nil } let(:sha) { nil }
let(:expected_ref) { 'master' } let(:expected_ref) { project.design_repository.root_ref }
it_behaves_like 'a successful request for sha' it_behaves_like 'a successful request for sha'
end end
......
...@@ -191,8 +191,8 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla ...@@ -191,8 +191,8 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla
expect(commits_on_master(limit: 99)).to include(*target_issue.design_versions.ordered.pluck(:sha)) expect(commits_on_master(limit: 99)).to include(*target_issue.design_versions.ordered.pluck(:sha))
end end
it 'creates a master branch if none previously existed' do it 'creates a default branch if none previously existed' do
expect { subject }.to change { target_repository.branch_names }.from([]).to(['master']) expect { subject }.to change { target_repository.branch_names }.from([]).to([project.design_repository.root_ref])
end end
it 'does not create default branch when one exists' do it 'does not create default branch when one exists' do
...@@ -255,7 +255,7 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla ...@@ -255,7 +255,7 @@ RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitla
end end
def commits_on_master(limit: 10) def commits_on_master(limit: 10)
target_repository.commits('master', limit: limit).map(&:id) target_repository.commits(target_repository.root_ref, limit: limit).map(&:id)
end end
end end
end end
......
...@@ -177,6 +177,18 @@ RSpec.describe DesignManagement::SaveDesignsService do ...@@ -177,6 +177,18 @@ RSpec.describe DesignManagement::SaveDesignsService do
end end
end end
context 'when HEAD branch is different from master' do
before do
stub_feature_flags(main_branch_over_master: true)
end
it 'does not raise an exception during update' do
run_service
expect { run_service }.not_to raise_error
end
end
context 'when a design is being updated' do context 'when a design is being updated' do
before do before do
run_service run_service
...@@ -343,7 +355,7 @@ RSpec.describe DesignManagement::SaveDesignsService do ...@@ -343,7 +355,7 @@ RSpec.describe DesignManagement::SaveDesignsService do
path = File.join(build(:design, issue: issue, filename: filename).full_path) path = File.join(build(:design, issue: issue, filename: filename).full_path)
design_repository.create_if_not_exists design_repository.create_if_not_exists
design_repository.create_file(user, path, 'something fake', design_repository.create_file(user, path, 'something fake',
branch_name: 'master', branch_name: project.default_branch_or_main,
message: 'Somehow created without being tracked in db') message: 'Somehow created without being tracked in db')
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