~cytrogen/masto-fe

ref: 68b4e36c82344fba7c5a01e9f8dc9ddbaaf4e3ff masto-fe/spec/lib/mastodon/cli/cache_spec.rb -rw-r--r-- 1.8 KiB
68b4e36c — Eugen Rochko Fix `#hashtag` matching non-hashtagged posts in search (#26781) 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

require 'rails_helper'
require 'mastodon/cli/cache'

describe Mastodon::CLI::Cache do
  let(:cli) { described_class.new }

  describe '.exit_on_failure?' do
    it 'returns true' do
      expect(described_class.exit_on_failure?).to be true
    end
  end

  describe '#clear' do
    before { allow(Rails.cache).to receive(:clear) }

    it 'clears the Rails cache' do
      expect { cli.invoke(:clear) }.to output(
        a_string_including('OK')
      ).to_stdout
      expect(Rails.cache).to have_received(:clear)
    end
  end

  describe '#recount' do
    context 'with the `accounts` argument' do
      let(:arguments) { ['accounts'] }
      let(:account_stat) { Fabricate(:account_stat) }

      before do
        account_stat.update(statuses_count: 123)
      end

      it 're-calculates account records in the cache' do
        expect { cli.invoke(:recount, arguments) }.to output(
          a_string_including('OK')
        ).to_stdout

        expect(account_stat.reload.statuses_count).to be_zero
      end
    end

    context 'with the `statuses` argument' do
      let(:arguments) { ['statuses'] }
      let(:status_stat) { Fabricate(:status_stat) }

      before do
        status_stat.update(replies_count: 123)
      end

      it 're-calculates account records in the cache' do
        expect { cli.invoke(:recount, arguments) }.to output(
          a_string_including('OK')
        ).to_stdout

        expect(status_stat.reload.replies_count).to be_zero
      end
    end

    context 'with an unknown type' do
      let(:arguments) { ['other-type'] }

      it 'Exits with an error message' do
        expect { cli.invoke(:recount, arguments) }.to output(
          a_string_including('Unknown')
        ).to_stdout.and raise_error(SystemExit)
      end
    end
  end
end