<commit_before>require "test_helper"

describe "background_delete plugin" do
  def attacher(&block)
    super() { plugin :background_delete, &block }
  end

  it "calls the block when replacing" do
    called = false
    @attacher = attacher { |uploaded_file, context| called = true }
    @attacher.set(fakeio)
    @attacher.set(fakeio)
    @attacher.replace

    assert called
  end

  it "calls the block when destroying" do
    called = false
    @attacher = attacher { |uploaded_file, context| called = true }
    @attacher.set(fakeio)
    @attacher.destroy

    assert called
  end
end
<commit_msg>Update background_delete tests to use fibers<commit_after>require "test_helper"

describe "background_delete plugin" do
  def attacher(&block)
    super() { plugin :background_delete, &block }
  end

  it "enables background deleting when replacing" do
    @attacher = attacher do |uploaded_file, context|
      @fiber = Fiber.new { uploaded_file.delete }
    end
    uploaded_file = @attacher.set(fakeio)
    @attacher.set(fakeio)
    @attacher.replace

    assert uploaded_file.exists?
    @fiber.resume
    refute uploaded_file.exists?
  end

  it "enables background deleting when destroying" do
    @attacher = attacher do |uploaded_file, context|
      @fiber = Fiber.new { uploaded_file.delete }
    end
    uploaded_file = @attacher.set(fakeio)
    @attacher.destroy
    @attacher.replace

    assert uploaded_file.exists?
    @fiber.resume
    refute uploaded_file.exists?
  end
end

{'fraction_non_alphanumeric': 0.08695652173913043, 'fraction_numerical': 0.0, 'mean_word_length': 3.4790419161676644, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7233482', 'n_tokens_mistral': 486, 'n_tokens_neox': 468, 'n_words': 126}