Commit 1268c17e authored by Nick Thomas's avatar Nick Thomas

Merge branch '227271-move-gitlab-currentsettings-default_branch_name-to-project' into 'master'

Add `Gitlab::CurrentSettings.default_branch_name` fallback to #default_branch

See merge request gitlab-org/gitlab!36231
parents d5e1b095 e7a20c34
......@@ -76,7 +76,11 @@ module HasRepository
end
def default_branch
@default_branch ||= repository.root_ref
@default_branch ||= repository.root_ref || default_branch_from_preferences
end
def default_branch_from_preferences
empty_repo? ? Gitlab::CurrentSettings.default_branch_name : nil
end
def reload_default_branch
......
......@@ -67,6 +67,7 @@ RSpec.describe 'Projects > Show > User sees Git instructions' do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.at_least(:once)
.and_return('example_branch')
sign_in(project.owner)
......
......@@ -63,6 +63,23 @@ RSpec.describe 'Projects > Show > User sees setup shortcut buttons' do
expect(page).to have_link('Add LICENSE', href: presenter.add_license_path)
end
end
context 'Gitlab::CurrentSettings.default_branch_name is available' do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.at_least(:once)
.and_return('example_branch')
visit project_path(project)
end
it '"New file" button linked to new file page' do
page.within('.project-buttons') do
expect(page).to have_link('New file', href: project_new_blob_path(project, 'example_branch'))
end
end
end
end
end
......
......@@ -4863,6 +4863,36 @@ RSpec.describe Project do
end
end
describe "#default_branch" do
context "with an empty repository" do
let_it_be(:project) { create(:project_empty_repo) }
context "Gitlab::CurrentSettings.default_branch_name is unavailable" do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return(nil)
end
it "returns that value" do
expect(project.default_branch).to be_nil
end
end
context "Gitlab::CurrentSettings.default_branch_name is available" do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.and_return('example_branch')
end
it "returns that value" do
expect(project.default_branch).to eq("example_branch")
end
end
end
end
describe '#to_ability_name' do
it 'returns project' do
project = build(:project_empty_repo)
......
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