Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil urls for skipped versions #117

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/arc_ecto/definition.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ defmodule Arc.Ecto.Definition do
if options[:signed] do
url
else
case updated_at do
%NaiveDateTime{} ->
case {url, updated_at} do
{nil, _} -> nil

{_, %NaiveDateTime{}} ->
version_url(updated_at, url)

string when is_bitstring(updated_at) ->
{_, string} when is_bitstring(updated_at) ->
version_url(NaiveDateTime.from_iso8601!(string), url)

_ ->
Expand All @@ -31,7 +33,7 @@ defmodule Arc.Ecto.Definition do
end

def url(f, v, options), do: super(f, v, options)

def delete({%{file_name: file_name, updated_at: _updated_at}, scope}), do: super({file_name, scope})

def delete(args), do: super(args)
Expand Down
6 changes: 6 additions & 0 deletions test/definition_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ defmodule ArcTest.Ecto.Definition do
url = DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: nil}, :scope}, :original, [])
assert url == "fallback"
end

test "url is nil if version is skipped" do
updated_at = NaiveDateTime.from_erl!({{2015, 1, 1}, {1, 1, 1}})
url = DummyDefinitionTwo.url({%{file_name: "test.png", updated_at: updated_at}, :scope}, :skipped, [])
assert is_nil(url)
end
end
1 change: 1 addition & 0 deletions test/support/dummy_definition_two.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule DummyDefinitionTwo do
def url(_, :skipped, _), do: nil
def url(_, :original, _), do: "fallback"
def url(_, :signed, _), do: "fallback?a=1&b=2"
def store({file, _}), do: {:ok, file}
Expand Down