2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-06-13 04:39:47 -04:00
|
|
|
require "spec_helper"
|
2016-11-22 11:58:10 -05:00
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe StorageHelper do
|
2018-06-13 04:39:47 -04:00
|
|
|
describe "#storage_counter" do
|
|
|
|
it "formats bytes to one decimal place" do
|
|
|
|
expect(helper.storage_counter(1.23.megabytes)).to eq("1.2 MB")
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
|
2018-06-13 04:39:47 -04:00
|
|
|
it "does not add decimals for sizes < 1 MB" do
|
|
|
|
expect(helper.storage_counter(23.5.kilobytes)).to eq("24 KB")
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
|
2018-06-13 04:39:47 -04:00
|
|
|
it "does not add decimals for zeroes" do
|
|
|
|
expect(helper.storage_counter(2.megabytes)).to eq("2 MB")
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
|
2018-06-13 04:39:47 -04:00
|
|
|
it "uses commas as thousands separator" do
|
2018-12-15 04:06:56 -05:00
|
|
|
expect(helper.storage_counter(100_000_000_000_000_000_000_000)).to eq("86,736.2 EB")
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
2019-05-02 12:04:15 -04:00
|
|
|
|
|
|
|
describe "#storage_counters_details" do
|
|
|
|
let(:namespace) { create :namespace }
|
|
|
|
let(:project) do
|
|
|
|
create(:project,
|
|
|
|
namespace: namespace,
|
|
|
|
statistics: build(:project_statistics,
|
|
|
|
repository_size: 10.kilobytes,
|
2019-02-13 17:38:11 -05:00
|
|
|
wiki_size: 10.bytes,
|
2019-05-02 12:04:15 -04:00
|
|
|
lfs_objects_size: 20.gigabytes,
|
2020-06-30 08:08:57 -04:00
|
|
|
build_artifacts_size: 30.megabytes,
|
|
|
|
snippets_size: 40.megabytes))
|
2019-05-02 12:04:15 -04:00
|
|
|
end
|
|
|
|
|
2020-06-30 08:08:57 -04:00
|
|
|
let(:message) { 'Repository: 10 KB / Wikis: 10 Bytes / Build Artifacts: 30 MB / LFS: 20 GB / Snippets: 40 MB' }
|
2019-05-02 12:04:15 -04:00
|
|
|
|
|
|
|
it 'works on ProjectStatistics' do
|
|
|
|
expect(helper.storage_counters_details(project.statistics)).to eq(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'works on Namespace.with_statistics' do
|
|
|
|
namespace_stats = Namespace.with_statistics.find(project.namespace.id)
|
|
|
|
|
|
|
|
expect(helper.storage_counters_details(namespace_stats)).to eq(message)
|
|
|
|
end
|
|
|
|
end
|
2016-11-22 11:58:10 -05:00
|
|
|
end
|