~cytrogen/masto-fe

ref: 0cb343eec2086809564455319b4bc3f1343c5dd4 masto-fe/spec/lib/cache_buster_spec.rb -rw-r--r-- 1.4 KiB
0cb343ee — Claire Tag nightly images as `latest` in glitch-soc, as it has no proper releases (#2414) 2 years ago
                                                                                
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
# frozen_string_literal: true

require 'rails_helper'

describe CacheBuster do
  subject { described_class.new(secret_header: secret_header, secret: secret, http_method: http_method) }

  let(:secret_header) { nil }
  let(:secret) { nil }
  let(:http_method) { nil }

  let(:purge_url) { 'https://example.com/test_purge' }

  describe '#bust' do
    shared_examples 'makes_request' do
      it 'makes an HTTP purging request' do
        method = http_method&.to_sym || :get
        stub_request(method, purge_url).to_return(status: 200)

        subject.bust(purge_url)

        test_request = a_request(method, purge_url)

        test_request = test_request.with(headers: { secret_header => secret }) if secret && secret_header

        expect(test_request).to have_been_made.once
      end
    end

    context 'when using default options' do
      include_examples 'makes_request'
    end

    context 'when specifying a secret header' do
      let(:secret_header) { 'X-Purge-Secret' }
      let(:secret) { SecureRandom.hex(20) }

      include_examples 'makes_request'
    end

    context 'when specifying a PURGE method' do
      let(:http_method) { 'purge' }

      context 'when not using headers' do
        include_examples 'makes_request'
      end

      context 'when specifying a secret header' do
        let(:secret_header) { 'X-Purge-Secret' }
        let(:secret) { SecureRandom.hex(20) }

        include_examples 'makes_request'
      end
    end
  end
end