debian-mirror-gitlab/spec/helpers/storage_helper_spec.rb

51 lines
1.7 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require "spec_helper"
2017-08-17 22:00:37 +05:30
2020-07-28 23:09:34 +05:30
RSpec.describe StorageHelper do
2018-11-08 19:23:39 +05:30
describe "#storage_counter" do
it "formats bytes to one decimal place" do
expect(helper.storage_counter(1.23.megabytes)).to eq("1.2 MB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "does not add decimals for sizes < 1 MB" do
expect(helper.storage_counter(23.5.kilobytes)).to eq("24 KB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "does not add decimals for zeroes" do
expect(helper.storage_counter(2.megabytes)).to eq("2 MB")
2017-08-17 22:00:37 +05:30
end
2018-11-08 19:23:39 +05:30
it "uses commas as thousands separator" do
2019-02-15 15:39:39 +05:30
expect(helper.storage_counter(100_000_000_000_000_000_000_000)).to eq("86,736.2 EB")
2017-08-17 22:00:37 +05:30
end
end
2019-07-31 22:56:46 +05:30
describe "#storage_counters_details" do
2020-11-24 15:15:51 +05:30
let_it_be(:namespace) { create(:namespace) }
let_it_be(:project) do
2019-07-31 22:56:46 +05:30
create(:project,
namespace: namespace,
statistics: build(:project_statistics,
2020-11-24 15:15:51 +05:30
namespace: namespace,
2019-07-31 22:56:46 +05:30
repository_size: 10.kilobytes,
2019-09-04 21:01:54 +05:30
wiki_size: 10.bytes,
2019-07-31 22:56:46 +05:30
lfs_objects_size: 20.gigabytes,
2020-07-28 23:09:34 +05:30
build_artifacts_size: 30.megabytes,
snippets_size: 40.megabytes))
2019-07-31 22:56:46 +05:30
end
2020-07-28 23:09:34 +05:30
let(:message) { 'Repository: 10 KB / Wikis: 10 Bytes / Build Artifacts: 30 MB / LFS: 20 GB / Snippets: 40 MB' }
2019-07-31 22:56:46 +05:30
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
2017-08-17 22:00:37 +05:30
end