require "test_helper"
require "shrine/plugins/keep_files"

describe Shrine::Plugins::KeepFiles do
  before do
    @attacher = attacher { plugin :keep_files }
  end

  describe "Attacher" do
    describe "#destroy_attached" do
      it "keeps files" do
        @attacher.attach(fakeio)
        @attacher.destroy_attached

        assert @attacher.file.exists?
      end
    end

    describe "#destroy_previous" do
      it "keep files" do
        previous_file = @attacher.attach(fakeio)
        @attacher.attach(fakeio)
        @attacher.destroy_previous

        assert previous_file.exists?
      end
    end
  end
end

require "test_helper"
require "shrine/plugins/keep_files"

describe Shrine::Plugins::KeepFiles do
  before do
    @attacher = attacher { plugin :keep_files }
    @shrine   = @attacher.shrine_class
  end

  describe "Attacher" do
    describe "#destroy_attached" do
      it "keeps files" do
        @attacher.attach(fakeio)
        @attacher.destroy_attached

        assert @attacher.file.exists?
      end

      it "doesn't spawn a background job" do
        @shrine.plugin :backgrounding
        @attacher.destroy_block { @called = true }

        @attacher.attach(fakeio)
        @attacher.destroy_attached

        assert @attacher.file.exists?
        refute @called
      end
    end

    describe "#destroy_previous" do
      it "keep files" do
        previous_file = @attacher.attach(fakeio)
        @attacher.attach(fakeio)
        @attacher.destroy_previous

        assert previous_file.exists?
      end

      it "doesn't spawn a background job" do
        @shrine.plugin :backgrounding
        @attacher.destroy_block { @called = true }

        previous_file = @attacher.attach(fakeio)
        @attacher.attach(fakeio)
        @attacher.destroy_previous

        assert previous_file.exists?
        refute @called
      end
    end
  end
end

Add tests that keep_files plays well with backgrounding
Add tests that keep_files plays well with backgrounding

One of the reasons why we've split Attacher#destroy_attached and
Attacher#destroy is so that we can skip the background job when
keep_files plugin is loaded. So we ought to add a test for that.
