Commit 9bf172f8 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '330622-show-default-default-branch-for-empty-projects' into 'master'

Show the default "default branch" in the API for empty projects

See merge request gitlab-org/gitlab!64944
parents d0c34b9c 5ce07d49
......@@ -6,7 +6,7 @@ module API
include ::API::ProjectsRelationBuilder
include Gitlab::Utils::StrongMemoize
expose :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
expose :default_branch_or_main, as: :default_branch, if: -> (project, options) { Ability.allowed?(options[:current_user], :download_code, project) }
# Avoids an N+1 query: https://github.com/mbleigh/acts-as-taggable-on/issues/91#issuecomment-168273770
expose :topic_names, as: :tag_list
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe API::Entities::BasicProjectDetails do
let_it_be(:project) { create(:project) }
let(:current_user) { project.owner }
subject(:output) { described_class.new(project, current_user: current_user).as_json }
describe '#default_branch' do
it 'delegates to Project#default_branch_or_main' do
expect(project).to receive(:default_branch_or_main).twice.and_call_original
expect(output).to include(default_branch: project.default_branch_or_main)
end
context 'anonymous user' do
let(:current_user) { nil }
it 'is not included' do
expect(output.keys).not_to include(:default_branch)
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