summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/pages/cache_control_spec.rb
blob: 6ed823427fb2676159c663d565f88e2219e5f02f (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Pages::CacheControl do
  it 'fails with invalid type' do
    expect { described_class.new(type: :unknown, id: nil) }
      .to raise_error(ArgumentError, "type must be :namespace or :project")
  end

  describe '.for_namespace' do
    let(:subject) { described_class.for_namespace(1) }

    it { expect(subject.cache_key).to eq('pages_domain_for_namespace_1') }

    describe '#clear_cache' do
      it 'clears the cache' do
        expect(Rails.cache)
          .to receive(:delete)
          .with('pages_domain_for_namespace_1')

        subject.clear_cache
      end
    end
  end

  describe '.for_project' do
    let(:subject) { described_class.for_project(1) }

    it { expect(subject.cache_key).to eq('pages_domain_for_project_1') }

    describe '#clear_cache' do
      it 'clears the cache' do
        expect(Rails.cache)
          .to receive(:delete)
          .with('pages_domain_for_project_1')

        subject.clear_cache
      end
    end
  end
end