Skip to content

Commit

Permalink
Bypass delete on skipped versions (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
achempion authored Aug 30, 2019
2 parents 0aff862 + 6166042 commit c378e0d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lib/waffle/actions/delete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ defmodule Waffle.Actions.Delete do
end

defp delete_version(definition, version, {file, scope}) do
definition.__storage.delete(definition, version, {file, scope})
conversion = definition.transform(version, {file, scope})
if conversion == :skip do
:ok
else
definition.__storage.delete(definition, version, {file, scope})
end
end
end
14 changes: 10 additions & 4 deletions test/storage/local_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ defmodule WaffleTest.Storage.Local do


defmodule DummyDefinition do
use Waffle.Actions.Store
use Waffle.Definition.Storage
use Waffle.Actions.Url
use Waffle.Definition

@acl :public_read
@versions [:original, :thumb, :skipped]

def transform(:thumb, _), do: {:convert, "-strip -thumbnail 10x10"}
def transform(:original, _), do: :noaction
def transform(:skipped, _), do: :skip
def __versions, do: [:original, :thumb, :skipped]

def storage_dir(_, _), do: "waffletest/uploads"
def __storage, do: Waffle.Storage.Local

def filename(:original, {file, _}), do: "original-#{Path.basename(file.file_name, Path.extname(file.file_name))}"
def filename(:thumb, {file, _}), do: "1/thumb-#{Path.basename(file.file_name, Path.extname(file.file_name))}"
def filename(:skipped, {file, _}), do: "1/skipped-#{Path.basename(file.file_name, Path.extname(file.file_name))}"
Expand All @@ -44,6 +45,11 @@ defmodule WaffleTest.Storage.Local do
refute File.exists?("waffletest/uploads/1/thumb-image.png")
end

test "deleting when there's a skipped version" do
DummyDefinition.store(@img)
assert :ok = DummyDefinition.delete(@img)
end

test "save binary" do
Waffle.Storage.Local.put(DummyDefinition, :original, {Waffle.File.new(%{binary: "binary", filename: "binary.png"}), nil})
assert true == File.exists?("waffletest/uploads/binary.png")
Expand Down

0 comments on commit c378e0d

Please sign in to comment.