More tests

This commit is contained in:
Thomas Citharel
2018-08-24 11:34:00 +02:00
parent a3852f26c1
commit 686cf04787
29 changed files with 945 additions and 241 deletions

View File

@@ -21,17 +21,23 @@ defmodule Eventos.Events.Comment do
belongs_to(:in_reply_to_comment, Comment, foreign_key: :in_reply_to_comment_id)
belongs_to(:origin_comment, Comment, foreign_key: :origin_comment_id)
timestamps()
timestamps(type: :utc_datetime)
end
@doc false
def changeset(comment, attrs) do
uuid = Ecto.UUID.generate()
# TODO : really change me right away
url =
if Map.has_key?(attrs, "url"),
do: attrs["url"],
else: "#{EventosWeb.Endpoint.url()}/comments/#{uuid}"
comment
|> cast(attrs, [:url, :text, :actor_id, :event_id, :in_reply_to_comment_id, :attributed_to_id])
|> validate_required([:text, :actor_id])
|> put_change(:uuid, uuid)
|> put_change(:url, "#{EventosWeb.Endpoint.url()}/comments/#{uuid}")
|> put_change(:url, url)
|> validate_required([:text, :actor_id, :url])
end
end