aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/jobs/purge_job_test.rb
blob: ed4100b78d8a008a6b047e7f690275ad80068716 (plain) (blame)
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
# frozen_string_literal: true

require "test_helper"
require "database/setup"

class ActiveStorage::PurgeJobTest < ActiveJob::TestCase
  setup { @blob = create_blob }

  test "purges" do
    assert_difference -> { ActiveStorage::Blob.count }, -1 do
      ActiveStorage::PurgeJob.perform_now @blob
    end

    assert_not ActiveStorage::Blob.exists?(@blob.id)
    assert_not ActiveStorage::Blob.service.exist?(@blob.key)
  end

  test "ignores missing blob" do
    @blob.purge

    perform_enqueued_jobs do
      assert_nothing_raised do
        ActiveStorage::PurgeJob.perform_later @blob
      end
    end
  end

  test "ignores attached blob" do
    User.create! name: "DHH", avatar: @blob

    perform_enqueued_jobs do
      assert_nothing_raised do
        ActiveStorage::PurgeJob.perform_later @blob
      end
    end
  end
end