Skip to content

Commit 0116f69

Browse files
dmarkowachempion
authored andcommittedAug 30, 2019
Bypass delete on skipped versions
1 parent af7905c commit 0116f69

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

‎lib/waffle/actions/delete.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ defmodule Waffle.Actions.Delete do
4040
end
4141

4242
defp delete_version(definition, version, {file, scope}) do
43-
definition.__storage.delete(definition, version, {file, scope})
43+
conversion = definition.transform(version, {file, scope})
44+
if conversion == :skip do
45+
:ok
46+
else
47+
definition.__storage.delete(definition, version, {file, scope})
48+
end
4449
end
4550
end

‎test/storage/local_test.exs

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ defmodule WaffleTest.Storage.Local do
1313

1414

1515
defmodule DummyDefinition do
16-
use Waffle.Actions.Store
17-
use Waffle.Definition.Storage
18-
use Waffle.Actions.Url
16+
use Waffle.Definition
1917

2018
@acl :public_read
2119
def transform(:thumb, _), do: {:convert, "-strip -thumbnail 10x10"}
@@ -44,6 +42,11 @@ defmodule WaffleTest.Storage.Local do
4442
refute File.exists?("waffletest/uploads/1/thumb-image.png")
4543
end
4644

45+
test "deleting when there's a skipped version" do
46+
DummyDefinition.store(@img)
47+
assert :ok = DummyDefinition.delete(@img)
48+
end
49+
4750
test "save binary" do
4851
Waffle.Storage.Local.put(DummyDefinition, :original, {Waffle.File.new(%{binary: "binary", filename: "binary.png"}), nil})
4952
assert true == File.exists?("waffletest/uploads/binary.png")

0 commit comments

Comments
 (0)
Please sign in to comment.