Welcome to mirror list, hosted at ThFree Co, Russian Federation.

root_storage_size_spec.rb « namespace « models « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a8048b7f6377b3c2e0a7475541bc0efb69a0cb90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Namespace::RootStorageSize, type: :model do
  let(:namespace) { create(:namespace) }
  let(:current_size) { 50.megabytes }
  let(:limit) { 100 }
  let(:model) { described_class.new(namespace) }
  let(:create_statistics) { create(:namespace_root_storage_statistics, namespace: namespace, storage_size: current_size)}

  before do
    create_statistics

    stub_application_setting(namespace_storage_size_limit: limit)
  end

  describe '#above_size_limit?' do
    subject { model.above_size_limit? }

    context 'when limit is 0' do
      let(:limit) { 0 }

      it { is_expected.to eq(false) }
    end

    context 'when below limit' do
      it { is_expected.to eq(false) }
    end

    context 'when above limit' do
      let(:current_size) { 101.megabytes }

      it { is_expected.to eq(true) }
    end
  end

  describe '#usage_ratio' do
    subject { model.usage_ratio }

    it { is_expected.to eq(0.5) }

    context 'when limit is 0' do
      let(:limit) { 0 }

      it { is_expected.to eq(0) }
    end

    context 'when there are no root_storage_statistics' do
      let(:create_statistics) { nil }

      it { is_expected.to eq(0) }
    end
  end

  describe '#current_size' do
    subject { model.current_size }

    it { is_expected.to eq(current_size) }
  end

  describe '#limit' do
    subject { model.limit }

    it { is_expected.to eq(limit.megabytes) }
  end
end