Fix an error in projects admin when statistics are missing
Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
parent
fcc810a1d9
commit
ec07641435
7 changed files with 64 additions and 5 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
module StorageHelper
|
||||
def storage_counter(size_in_bytes)
|
||||
return s_('StorageSize|Unknown') unless size_in_bytes
|
||||
|
||||
precision = size_in_bytes < 1.megabyte ? 0 : 1
|
||||
|
||||
number_to_human_size(size_in_bytes, delimiter: ',', precision: precision, significant: false)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
.stats
|
||||
%span.badge.badge-pill
|
||||
= storage_counter(project.statistics.storage_size)
|
||||
= storage_counter(project.statistics&.storage_size)
|
||||
- if project.archived
|
||||
%span.badge.badge-warning archived
|
||||
.title
|
||||
|
|
|
@ -74,10 +74,10 @@
|
|||
|
||||
%li
|
||||
%span.light= _('Storage:')
|
||||
%strong= storage_counter(@project.statistics.storage_size)
|
||||
(
|
||||
= storage_counters_details(@project.statistics)
|
||||
)
|
||||
%strong= storage_counter(@project.statistics&.storage_size)
|
||||
- if @project.statistics
|
||||
= surround '(', ')' do
|
||||
= storage_counters_details(@project.statistics)
|
||||
|
||||
%li
|
||||
%span.light last commit:
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix an error in projects admin when statistics are missing
|
||||
merge_request: 28355
|
||||
author:
|
||||
type: fixed
|
|
@ -9146,6 +9146,9 @@ msgstr ""
|
|||
msgid "Storage:"
|
||||
msgstr ""
|
||||
|
||||
msgid "StorageSize|Unknown"
|
||||
msgstr ""
|
||||
|
||||
msgid "Subgroups"
|
||||
msgstr ""
|
||||
|
||||
|
|
29
spec/features/admin/admin_sees_project_statistics_spec.rb
Normal file
29
spec/features/admin/admin_sees_project_statistics_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Admin > Admin sees project statistics" do
|
||||
let(:current_user) { create(:admin) }
|
||||
|
||||
before do
|
||||
sign_in(current_user)
|
||||
|
||||
visit admin_project_path(project)
|
||||
end
|
||||
|
||||
context 'when project has statistics' do
|
||||
let(:project) { create(:project, :repository) }
|
||||
|
||||
it "shows project statistics" do
|
||||
expect(page).to have_content("Storage: 0 Bytes (0 Bytes repositories, 0 Bytes build artifacts, 0 Bytes LFS)")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when project has no statistics' do
|
||||
let(:project) { create(:project, :repository) { |project| project.statistics.destroy } }
|
||||
|
||||
it "shows 'Storage: Unknown'" do
|
||||
expect(page).to have_content("Storage: Unknown")
|
||||
end
|
||||
end
|
||||
end
|
20
spec/features/admin/admin_sees_projects_statistics_spec.rb
Normal file
20
spec/features/admin/admin_sees_projects_statistics_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe "Admin > Admin sees projects statistics" do
|
||||
let(:current_user) { create(:admin) }
|
||||
|
||||
before do
|
||||
create(:project, :repository)
|
||||
create(:project, :repository) { |project| project.statistics.destroy }
|
||||
|
||||
sign_in(current_user)
|
||||
|
||||
visit admin_projects_path
|
||||
end
|
||||
|
||||
it "shows project statistics for projects that have them" do
|
||||
expect(page.all('.stats').map(&:text)).to contain_exactly("0 Bytes", "Unknown")
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue