Commit 5588ea1e authored by Nick Thomas's avatar Nick Thomas

Merge branch '46963-add_readme_button_for_non_empty_project' into 'master'

Add readme button to non-empty project page

Closes #46963

See merge request gitlab-org/gitlab-ce!20104
parents 7054ead4 825b9435
...@@ -27,6 +27,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -27,6 +27,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
def statistics_buttons(show_auto_devops_callout:) def statistics_buttons(show_auto_devops_callout:)
[ [
readme_anchor_data,
changelog_anchor_data, changelog_anchor_data,
license_anchor_data, license_anchor_data,
contribution_guide_anchor_data, contribution_guide_anchor_data,
...@@ -212,11 +213,11 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -212,11 +213,11 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def readme_anchor_data def readme_anchor_data
if current_user && can_current_user_push_to_default_branch? && repository.readme.blank? if current_user && can_current_user_push_to_default_branch? && repository.readme.nil?
OpenStruct.new(enabled: false, OpenStruct.new(enabled: false,
label: _('Add Readme'), label: _('Add Readme'),
link: add_readme_path) link: add_readme_path)
elsif repository.readme.present? elsif repository.readme
OpenStruct.new(enabled: true, OpenStruct.new(enabled: true,
label: _('Readme'), label: _('Readme'),
link: default_view != 'readme' ? readme_path : '#readme') link: default_view != 'readme' ? readme_path : '#readme')
......
---
title: Add readme button to non-empty project page
merge_request: 20104
author:
type: fixed
...@@ -5,6 +5,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -5,6 +5,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
# see spec/features/projects/files/project_owner_creates_license_file_spec.rb # see spec/features/projects/files/project_owner_creates_license_file_spec.rb
# see spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb # see spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
include FakeBlobHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'empty project' do describe 'empty project' do
...@@ -141,11 +143,57 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -141,11 +143,57 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
allow_any_instance_of(AutoDevopsHelper).to receive(:show_auto_devops_callout?).and_return(false) allow_any_instance_of(AutoDevopsHelper).to receive(:show_auto_devops_callout?).and_return(false)
project.add_master(user) project.add_master(user)
sign_in(user) sign_in(user)
end
visit project_path(project) context 'Readme button' do
before do
allow(Project).to receive(:find_by_full_path)
.with(project.full_path, follow_redirects: true)
.and_return(project)
end
context 'when the project has a populated Readme' do
it 'show the "Readme" anchor' do
visit project_path(project)
expect(project.repository.readme).not_to be_nil
page.within('.project-stats') do
expect(page).not_to have_link('Add Readme', href: presenter.add_readme_path)
expect(page).to have_link('Readme', href: presenter.readme_path)
end
end
context 'when the project has an empty Readme' do
it 'show the "Readme" anchor' do
allow(project.repository).to receive(:readme).and_return(fake_blob(path: 'README.md', data: '', size: 0))
visit project_path(project)
page.within('.project-stats') do
expect(page).not_to have_link('Add Readme', href: presenter.add_readme_path)
expect(page).to have_link('Readme', href: presenter.readme_path)
end
end
end
end
context 'when the project does not have a Readme' do
it 'shows the "Add Readme" button' do
allow(project.repository).to receive(:readme).and_return(nil)
visit project_path(project)
page.within('.project-stats') do
expect(page).to have_link('Add Readme', href: presenter.add_readme_path)
end
end
end
end end
it 'no "Add Changelog" button if the project already has a changelog' do it 'no "Add Changelog" button if the project already has a changelog' do
visit project_path(project)
expect(project.repository.changelog).not_to be_nil expect(project.repository.changelog).not_to be_nil
page.within('.project-stats') do page.within('.project-stats') do
...@@ -154,6 +202,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -154,6 +202,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
end end
it 'no "Add License" button if the project already has a license' do it 'no "Add License" button if the project already has a license' do
visit project_path(project)
expect(project.repository.license_blob).not_to be_nil expect(project.repository.license_blob).not_to be_nil
page.within('.project-stats') do page.within('.project-stats') do
...@@ -162,6 +212,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -162,6 +212,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
end end
it 'no "Add Contribution guide" button if the project already has a contribution guide' do it 'no "Add Contribution guide" button if the project already has a contribution guide' do
visit project_path(project)
expect(project.repository.contribution_guide).not_to be_nil expect(project.repository.contribution_guide).not_to be_nil
page.within('.project-stats') do page.within('.project-stats') do
...@@ -171,6 +223,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -171,6 +223,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
describe 'GitLab CI configuration button' do describe 'GitLab CI configuration button' do
it '"Set up CI/CD" button linked to new file populated for a .gitlab-ci.yml' do it '"Set up CI/CD" button linked to new file populated for a .gitlab-ci.yml' do
visit project_path(project)
expect(project.repository.gitlab_ci_yml).to be_nil expect(project.repository.gitlab_ci_yml).to be_nil
page.within('.project-stats') do page.within('.project-stats') do
...@@ -211,6 +265,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -211,6 +265,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
describe 'Auto DevOps button' do describe 'Auto DevOps button' do
it '"Enable Auto DevOps" button linked to settings page' do it '"Enable Auto DevOps" button linked to settings page' do
visit project_path(project)
page.within('.project-stats') do page.within('.project-stats') do
expect(page).to have_link('Enable Auto DevOps', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings')) expect(page).to have_link('Enable Auto DevOps', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end end
...@@ -263,6 +319,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do ...@@ -263,6 +319,8 @@ describe 'Projects > Show > User sees setup shortcut buttons' do
describe 'Kubernetes cluster button' do describe 'Kubernetes cluster button' do
it '"Add Kubernetes cluster" button linked to clusters page' do it '"Add Kubernetes cluster" button linked to clusters page' do
visit project_path(project)
page.within('.project-stats') do page.within('.project-stats') do
expect(page).to have_link('Add Kubernetes cluster', href: new_project_cluster_path(project)) expect(page).to have_link('Add Kubernetes cluster', href: new_project_cluster_path(project))
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