run mix format

This commit is contained in:
Finn Behrens
2022-11-17 13:37:34 +01:00
parent 1dc9178350
commit a6418db196
42 changed files with 269 additions and 165 deletions

View File

@@ -83,8 +83,10 @@ if config_env() == :prod do
username: System.get_env("SMTP_USERNAME"), username: System.get_env("SMTP_USERNAME"),
password: System.get_env("SMTP_PASSWORD"), password: System.get_env("SMTP_PASSWORD"),
ssl: System.get_env("SMTP_SSL", "true") == "true", ssl: System.get_env("SMTP_SSL", "true") == "true",
tls: String.to_atom(System.get_env("SMTP_TLS", "always")), # always, never, if_available # always, never, if_available
auth: String.to_atom(System.get_env("SMTP_AUTH", "always")), # always, never, if_available tls: String.to_atom(System.get_env("SMTP_TLS", "always")),
# always, never, if_available
auth: String.to_atom(System.get_env("SMTP_AUTH", "always")),
port: String.to_integer(System.get_env("SMTP_PORT", "25")) port: String.to_integer(System.get_env("SMTP_PORT", "25"))
end end

View File

@@ -410,9 +410,11 @@ defmodule Claper.Accounts do
Ecto.Multi.new() Ecto.Multi.new()
|> Ecto.Multi.run(:run, fn repo, _changes -> |> Ecto.Multi.run(:run, fn repo, _changes ->
user = repo.get_by(User, email: token.sent_to) user = repo.get_by(User, email: token.sent_to)
if (is_nil(user)) do
if is_nil(user) do
UserNotifier.deliver_welcome(token.sent_to) UserNotifier.deliver_welcome(token.sent_to)
end end
{:ok, user || %User{email: token.sent_to}} {:ok, user || %User{email: token.sent_to}}
end) end)
|> Ecto.Multi.insert_or_update(:user, fn %{run: user} -> User.confirm_changeset(user) end) |> Ecto.Multi.insert_or_update(:user, fn %{run: user} -> User.confirm_changeset(user) end)

View File

@@ -111,5 +111,4 @@ defmodule Claper.Accounts.User do
add_error(changeset, :current_password, "is not valid") add_error(changeset, :current_password, "is not valid")
end end
end end
end end

View File

@@ -19,6 +19,7 @@ defmodule Claper.Accounts.UserNotifier do
def deliver_magic_link(email, url) do def deliver_magic_link(email, url) do
email = ClaperWeb.Notifiers.UserNotifier.magic(email, url) email = ClaperWeb.Notifiers.UserNotifier.magic(email, url)
with {:ok, _metadata} <- Mailer.deliver(email) do with {:ok, _metadata} <- Mailer.deliver(email) do
{:ok, email} {:ok, email}
end end
@@ -26,6 +27,7 @@ defmodule Claper.Accounts.UserNotifier do
def deliver_welcome(email) do def deliver_welcome(email) do
email = ClaperWeb.Notifiers.UserNotifier.welcome(email) email = ClaperWeb.Notifiers.UserNotifier.welcome(email)
with {:ok, _metadata} <- Mailer.deliver(email) do with {:ok, _metadata} <- Mailer.deliver(email) do
{:ok, email} {:ok, email}
end end
@@ -76,6 +78,7 @@ defmodule Claper.Accounts.UserNotifier do
""" """
def deliver_update_email_instructions(user, url) do def deliver_update_email_instructions(user, url) do
email = ClaperWeb.Notifiers.UserNotifier.update_email(user, url) email = ClaperWeb.Notifiers.UserNotifier.update_email(user, url)
with {:ok, _metadata} <- Mailer.deliver(email) do with {:ok, _metadata} <- Mailer.deliver(email) do
{:ok, email} {:ok, email}
end end

View File

@@ -95,7 +95,10 @@ defmodule Claper.Events do
""" """
def get_managed_event!(current_user, id, preload \\ []) do def get_managed_event!(current_user, id, preload \\ []) do
event = Repo.get_by!(Event, uuid: id) event = Repo.get_by!(Event, uuid: id)
is_leader = Claper.Events.is_leaded_by(current_user.email, event) || event.user_id == current_user.id
is_leader =
Claper.Events.is_leaded_by(current_user.email, event) || event.user_id == current_user.id
if is_leader do if is_leader do
event |> Repo.preload(preload) event |> Repo.preload(preload)
else else

View File

@@ -167,7 +167,6 @@ defmodule Claper.Polls do
{:error, changeset} -> {:error, changeset} ->
{:error, %{changeset | action: :update}} {:error, %{changeset | action: :update}}
end end
end end
@doc """ @doc """
@@ -306,7 +305,6 @@ defmodule Claper.Polls do
{:ok, poll} {:ok, poll}
end end
@doc """ @doc """
Gets a single poll_vote. Gets a single poll_vote.

View File

@@ -176,6 +176,7 @@ defmodule Claper.Posts do
""" """
def create_reaction(%{post: nil} = attrs), do: create_reaction(%{attrs | post: %Post{}}) def create_reaction(%{post: nil} = attrs), do: create_reaction(%{attrs | post: %Post{}})
def create_reaction(%{post: post} = attrs) do def create_reaction(%{post: post} = attrs) do
case %Reaction{} case %Reaction{}
|> Map.put(:post_id, post.id) |> Map.put(:post_id, post.id)

View File

@@ -22,9 +22,16 @@ defmodule Claper.Posts.Post do
@doc false @doc false
def changeset(post, attrs) do def changeset(post, attrs) do
post post
|> cast(attrs, [:body, :attendee_identifier, :user_id, :like_count, :love_count, :lol_count, :position]) |> cast(attrs, [
:body,
:attendee_identifier,
:user_id,
:like_count,
:love_count,
:lol_count,
:position
])
|> validate_required([:body, :position]) |> validate_required([:body, :position])
|> validate_length(:body, min: 2, max: 250) |> validate_length(:body, min: 2, max: 250)
end end
end end

View File

@@ -17,7 +17,14 @@ defmodule Claper.Presentations.PresentationState do
@doc false @doc false
def changeset(presentation_state, attrs) do def changeset(presentation_state, attrs) do
presentation_state presentation_state
|> cast(attrs, [:position, :chat_visible, :poll_visible, :join_screen_visible, :banned, :presentation_file_id]) |> cast(attrs, [
:position,
:chat_visible,
:poll_visible,
:join_screen_visible,
:banned,
:presentation_file_id
])
|> validate_required([]) |> validate_required([])
end end
end end

View File

@@ -47,13 +47,14 @@ defmodule Claper.Tasks.Converter do
IO.puts("Clearing #{hash}...") IO.puts("Clearing #{hash}...")
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
File.rm_rf(Path.join([ File.rm_rf(
Path.join([
:code.priv_dir(:claper), :code.priv_dir(:claper),
"static", "static",
"uploads", "uploads",
"#{hash}" "#{hash}"
])) ])
)
else else
stream = stream =
ExAws.S3.list_objects(System.get_env("AWS_PRES_BUCKET"), prefix: "presentations/#{hash}") ExAws.S3.list_objects(System.get_env("AWS_PRES_BUCKET"), prefix: "presentations/#{hash}")
@@ -115,28 +116,27 @@ defmodule Claper.Tasks.Converter do
end end
defp jpg_upload(%Result{status: 0}, hash, path, presentation, user_id) do defp jpg_upload(%Result{status: 0}, hash, path, presentation, user_id) do
files = Path.wildcard("#{path}/*.jpg") files = Path.wildcard("#{path}/*.jpg")
# assign new hash to avoid cache issues # assign new hash to avoid cache issues
new_hash = :erlang.phash2("#{hash}-#{System.system_time(:second)}") new_hash = :erlang.phash2("#{hash}-#{System.system_time(:second)}")
if System.get_env("PRESENTATION_STORAGE", "local") == "local" do if System.get_env("PRESENTATION_STORAGE", "local") == "local" do
File.rename(
File.rename(Path.join([ Path.join([
:code.priv_dir(:claper), :code.priv_dir(:claper),
"static", "static",
"uploads", "uploads",
"#{hash}" "#{hash}"
]), Path.join([ ]),
Path.join([
:code.priv_dir(:claper), :code.priv_dir(:claper),
"static", "static",
"uploads", "uploads",
"#{new_hash}" "#{new_hash}"
])) ])
)
else else
for f <- files do for f <- files do
IO.puts("Uploads #{f} to presentations/#{new_hash}/#{Path.basename(f)}") IO.puts("Uploads #{f} to presentations/#{new_hash}/#{Path.basename(f)}")
@@ -149,7 +149,6 @@ defmodule Claper.Tasks.Converter do
) )
|> ExAws.request() |> ExAws.request()
end end
end end
if !is_nil(presentation.hash) do if !is_nil(presentation.hash) do

View File

@@ -5,6 +5,7 @@ defmodule ClaperWeb.Presence do
See the [`Phoenix.Presence`](http://hexdocs.pm/phoenix/Phoenix.Presence.html) See the [`Phoenix.Presence`](http://hexdocs.pm/phoenix/Phoenix.Presence.html)
docs for more details. docs for more details.
""" """
use Phoenix.Presence, otp_app: :claper, use Phoenix.Presence,
otp_app: :claper,
pubsub_server: Claper.PubSub pubsub_server: Claper.PubSub
end end

View File

@@ -8,22 +8,24 @@ defmodule ClaperWeb.PostController do
render(conn, "index.json", posts: posts) render(conn, "index.json", posts: posts)
end end
rescue rescue
Ecto.NoResultsError -> conn Ecto.NoResultsError ->
conn
|> put_status(:not_found) |> put_status(:not_found)
|> put_view(ClaperWeb.ErrorView) |> put_view(ClaperWeb.ErrorView)
|> render(:"404") |> render(:"404")
end end
end end
def create(conn, %{"event_id" => event_id, "body" => body}) do def create(conn, %{"event_id" => event_id, "body" => body}) do
try do try do
with event <- Claper.Events.get_event!(event_id) do with event <- Claper.Events.get_event!(event_id) do
case Claper.Posts.create_post(event, %{body: body}) do case Claper.Posts.create_post(event, %{body: body}) do
{:ok, post} -> render(conn, "post.json", post: post) {:ok, post} -> render(conn, "post.json", post: post)
end end
end end
rescue rescue
Ecto.NoResultsError -> conn Ecto.NoResultsError ->
conn
|> put_status(:not_found) |> put_status(:not_found)
|> put_view(ClaperWeb.ErrorView) |> put_view(ClaperWeb.ErrorView)
|> render(:"404") |> render(:"404")

View File

@@ -133,7 +133,7 @@ defmodule ClaperWeb.UserAuth do
conn conn
else else
conn conn
#|> redirect(to: Routes.user_registration_path(conn, :confirm)) # |> redirect(to: Routes.user_registration_path(conn, :confirm))
end end
else else
conn conn

View File

@@ -9,12 +9,12 @@ defmodule ClaperWeb.UserSessionController do
|> render("new.html", error_message: nil) |> render("new.html", error_message: nil)
end end
#def create(conn, %{"user" => %{"email" => email}} = _user_params) do # def create(conn, %{"user" => %{"email" => email}} = _user_params) do
# Accounts.deliver_magic_link(email, &Routes.user_confirmation_url(conn, :confirm_magic, &1)) # Accounts.deliver_magic_link(email, &Routes.user_confirmation_url(conn, :confirm_magic, &1))
# conn # conn
# |> redirect(to: Routes.user_registration_path(conn, :confirm, %{email: email})) # |> redirect(to: Routes.user_registration_path(conn, :confirm, %{email: email}))
#end # end
def create(conn, %{"user" => user_params}) do def create(conn, %{"user" => user_params}) do
%{"email" => email, "password" => password} = user_params %{"email" => email, "password" => password} = user_params

View File

@@ -153,7 +153,6 @@ defmodule ClaperWeb.EventLive.FormComponent do
end end
defp create_event(socket, event_params, hash, ext) do defp create_event(socket, event_params, hash, ext) do
case Events.create_event( case Events.create_event(
event_params event_params
|> Map.put("user_id", socket.assigns.current_user.id) |> Map.put("user_id", socket.assigns.current_user.id)

View File

@@ -90,5 +90,4 @@ defmodule ClaperWeb.EventLive.Index do
defp list_managed_events(socket) do defp list_managed_events(socket) do
Events.list_managed_events_by(socket.assigns.current_user.email, [:presentation_file]) Events.list_managed_events_by(socket.assigns.current_user.email, [:presentation_file])
end end
end end

View File

@@ -88,7 +88,6 @@ defmodule ClaperWeb.EventLive.Show do
{:ok, socket |> assign(:empty_room, Enum.count(socket.assigns.posts) == 0), {:ok, socket |> assign(:empty_room, Enum.count(socket.assigns.posts) == 0),
temporary_assigns: [posts: []]} temporary_assigns: [posts: []]}
end end
defp leader_list(socket, event) do defp leader_list(socket, event) do

View File

@@ -20,5 +20,4 @@ defmodule ClaperWeb.LiveHelpers do
modal_opts = [id: :modal, return_to: path, component: component, opts: opts] modal_opts = [id: :modal, return_to: path, component: component, opts: opts]
live_component(ClaperWeb.ModalComponent, modal_opts) live_component(ClaperWeb.ModalComponent, modal_opts)
end end
end end

View File

@@ -31,7 +31,10 @@ defmodule ClaperWeb.StatLive.Index do
grouped_total_votes grouped_total_votes
) )
|> assign(:average_voters, average_voters(grouped_total_votes)) |> assign(:average_voters, average_voters(grouped_total_votes))
|> assign(:engagement_rate, calculate_engagement_rate(grouped_total_votes, distinct_poster_count, event)) |> assign(
:engagement_rate,
calculate_engagement_rate(grouped_total_votes, distinct_poster_count, event)
)
|> assign(:posts, list_posts(socket, event.uuid))} |> assign(:posts, list_posts(socket, event.uuid))}
end end
@@ -49,9 +52,16 @@ defmodule ClaperWeb.StatLive.Index do
total_polls = Enum.count(grouped_total_votes) total_polls = Enum.count(grouped_total_votes)
if total_polls == 0 do if total_polls == 0 do
(distinct_poster_count/event.audience_peak) * 100 |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer (distinct_poster_count / event.audience_peak * 100)
|> Float.round()
|> :erlang.float_to_binary(decimals: 0)
|> :erlang.binary_to_integer()
else else
(((distinct_poster_count/event.audience_peak) + (average_voters(grouped_total_votes))/event.audience_peak) / 2) * 100 |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer ((distinct_poster_count / event.audience_peak +
average_voters(grouped_total_votes) / event.audience_peak) / 2 * 100)
|> Float.round()
|> :erlang.float_to_binary(decimals: 0)
|> :erlang.binary_to_integer()
end end
end end
@@ -61,9 +71,11 @@ defmodule ClaperWeb.StatLive.Index do
if total_polls == 0 do if total_polls == 0 do
0 0
else else
(Enum.sum(grouped_total_votes)/total_polls) |> Float.round |> :erlang.float_to_binary(decimals: 0) |> :erlang.binary_to_integer (Enum.sum(grouped_total_votes) / total_polls)
|> Float.round()
|> :erlang.float_to_binary(decimals: 0)
|> :erlang.binary_to_integer()
end end
end end
defp list_posts(_socket, event_id) do defp list_posts(_socket, event_id) do

View File

@@ -5,7 +5,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
def magic(email, url) do def magic(email, url) do
new() new()
|> to(email) |> to(email)
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")}) |> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
)
|> subject(gettext("Connect to Claper")) |> subject(gettext("Connect to Claper"))
|> render_body("magic.html", %{url: url}) |> render_body("magic.html", %{url: url})
end end
@@ -13,7 +16,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
def welcome(email) do def welcome(email) do
new() new()
|> to(email) |> to(email)
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")}) |> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
)
|> subject(gettext("Next steps to boost your presentations")) |> subject(gettext("Next steps to boost your presentations"))
|> render_body("welcome.html", %{email: email}) |> render_body("welcome.html", %{email: email})
end end
@@ -21,7 +27,10 @@ defmodule ClaperWeb.Notifiers.UserNotifier do
def update_email(user, url) do def update_email(user, url) do
new() new()
|> to(user.email) |> to(user.email)
|> from({System.get_env("MAIL_FROM_NAME", "Claper"), System.get_env("MAIL_FROM", "noreply@claper.co")}) |> from(
{System.get_env("MAIL_FROM_NAME", "Claper"),
System.get_env("MAIL_FROM", "noreply@claper.co")}
)
|> subject(gettext("Update email instructions")) |> subject(gettext("Update email instructions"))
|> render_body("change.html", %{user: user, url: url}) |> render_body("change.html", %{user: user, url: url})
end end

View File

@@ -4,9 +4,11 @@ defmodule ClaperWeb.Plugs.Locale do
def init(_opts), do: nil def init(_opts), do: nil
def call(conn, _opts) do def call(conn, _opts) do
known_locales = Gettext.known_locales(ClaperWeb.Gettext) known_locales = Gettext.known_locales(ClaperWeb.Gettext)
accepted_languages = extract_accept_language(conn) |> Enum.reject(&String.length(&1) > 2 && not Enum.member?(known_locales, &1))
accepted_languages =
extract_accept_language(conn)
|> Enum.reject(&(String.length(&1) > 2 && not Enum.member?(known_locales, &1)))
case accepted_languages do case accepted_languages do
[locale | _] -> [locale | _] ->

View File

@@ -88,8 +88,8 @@ defmodule ClaperWeb.Router do
# node running the Phoenix server. # node running the Phoenix server.
if Mix.env() == :dev || System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do if Mix.env() == :dev || System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
scope "/dev" do scope "/dev" do
if System.get_env("MAILBOX_USER") && System.get_env("MAILBOX_PASSWORD") &&
if System.get_env("MAILBOX_USER") && System.get_env("MAILBOX_PASSWORD") && System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do System.get_env("ENABLE_MAILBOX_ROUTE", "false") == "true" do
pipe_through [:browser, :protect_with_basic_auth] pipe_through [:browser, :protect_with_basic_auth]
else else
pipe_through [:browser] pipe_through [:browser]
@@ -142,5 +142,4 @@ defmodule ClaperWeb.Router do
password = System.fetch_env!("MAILBOX_PASSWORD") password = System.fetch_env!("MAILBOX_PASSWORD")
Plug.BasicAuth.basic_auth(conn, username: username, password: password) Plug.BasicAuth.basic_auth(conn, username: username, password: password)
end end
end end

View File

@@ -5,6 +5,7 @@ defmodule ClaperWeb.Component.Alert do
assigns = assigns =
assigns assigns
|> assign_new(:stick, fn -> false end) |> assign_new(:stick, fn -> false end)
~H""" ~H"""
<div class="bg-supporting-green-50 border-t-4 rounded-b-md shadow-md border-supporting-green-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition> <div class="bg-supporting-green-50 border-t-4 rounded-b-md shadow-md border-supporting-green-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition>
<div class="flex"> <div class="flex">
@@ -27,6 +28,7 @@ defmodule ClaperWeb.Component.Alert do
assigns = assigns =
assigns assigns
|> assign_new(:stick, fn -> false end) |> assign_new(:stick, fn -> false end)
~H""" ~H"""
<div class="bg-supporting-red-50 border-t-4 rounded-b-md shadow-md border-supporting-red-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition> <div class="bg-supporting-red-50 border-t-4 rounded-b-md shadow-md border-supporting-red-400 p-4 mb-3" x-data="{ open: true }" x-show={if @stick, do: "true", else: "open"} x-init="setTimeout(() => {open = false}, 4000)" x-transition>
<div class="flex"> <div class="flex">
@@ -45,5 +47,4 @@ defmodule ClaperWeb.Component.Alert do
</div> </div>
""" """
end end
end end

View File

@@ -7,6 +7,7 @@ defmodule ClaperWeb.LayoutView do
def active_class(conn, path) do def active_class(conn, path) do
current_path = Path.join(["/" | conn.path_info]) current_path = Path.join(["/" | conn.path_info])
if path == current_path do if path == current_path do
"bg-gray-900 text-white" "bg-gray-900 text-white"
else else
@@ -23,21 +24,28 @@ defmodule ClaperWeb.LayoutView do
end end
def active_link(%Plug.Conn{} = conn, text, opts) do def active_link(%Plug.Conn{} = conn, text, opts) do
class = [opts[:class], active_class(conn, opts[:to])] class =
[opts[:class], active_class(conn, opts[:to])]
|> Enum.filter(& &1) |> Enum.filter(& &1)
|> Enum.join(" ") |> Enum.join(" ")
opts = opts
opts =
opts
|> Keyword.put(:class, class) |> Keyword.put(:class, class)
link(text, opts) link(text, opts)
end end
def active_link(%Phoenix.LiveView.Socket{} = conn, text, opts) do def active_link(%Phoenix.LiveView.Socket{} = conn, text, opts) do
class = [opts[:class], active_live_class(conn, opts[:to])] class =
[opts[:class], active_live_class(conn, opts[:to])]
|> Enum.filter(& &1) |> Enum.filter(& &1)
|> Enum.join(" ") |> Enum.join(" ")
opts = opts
opts =
opts
|> Keyword.put(:class, class) |> Keyword.put(:class, class)
live_patch(text, opts) live_patch(text, opts)
end end
end end

View File

@@ -1,7 +1,6 @@
defmodule ClaperWeb.UserView do defmodule ClaperWeb.UserView do
use ClaperWeb, :view use ClaperWeb, :view
def render("user.json", %{user: user}) do def render("user.json", %{user: user}) do
%{ %{
uuid: user.uuid, uuid: user.uuid,

View File

@@ -1,10 +1,18 @@
defmodule Utils.FileUpload do defmodule Utils.FileUpload do
import Mogrify import Mogrify
def upload(type, path, old_path) when is_atom(type) do def upload(type, path, old_path) when is_atom(type) do
remove_old_file(old_path) remove_old_file(old_path)
dest = Path.join([:code.priv_dir(:claper), "static", "uploads", Atom.to_string(type), Path.basename(path)])
dest =
Path.join([
:code.priv_dir(:claper),
"static",
"uploads",
Atom.to_string(type),
Path.basename(path)
])
open(path) |> resize_to_fill("100x100") |> save(in_place: true) open(path) |> resize_to_fill("100x100") |> save(in_place: true)
File.cp!(path, dest) File.cp!(path, dest)
"/uploads/#{Atom.to_string(type)}/#{Path.basename(dest)}" "/uploads/#{Atom.to_string(type)}/#{Path.basename(dest)}"

View File

@@ -0,0 +1 @@

15
mix.exs
View File

@@ -28,7 +28,6 @@ defmodule Claper.MixProject do
"guides/introduction/configuration.md", "guides/introduction/configuration.md",
"guides/introduction/installation.md", "guides/introduction/installation.md",
"guides/introduction/storage.md", "guides/introduction/storage.md",
"guides/usage/features.md", "guides/usage/features.md",
"guides/usage/howto.md" "guides/usage/howto.md"
], ],
@@ -48,19 +47,19 @@ defmodule Claper.MixProject do
~r/ClaperWeb\.UserReset\.?/, ~r/ClaperWeb\.UserReset\.?/,
~r/ClaperWeb\.Attendee\.?/, ~r/ClaperWeb\.Attendee\.?/,
~r/ClaperWeb\.UserAuth\.?/, ~r/ClaperWeb\.UserAuth\.?/,
~r/ClaperWeb\.UserView\.?/, ~r/ClaperWeb\.UserView\.?/
], ],
"Events": [ Events: [
~r/Claper\.Event\.?/, ~r/Claper\.Event\.?/,
~r/ClaperWeb\.Event\.?/, ~r/ClaperWeb\.Event\.?/
], ],
"Polls": [ Polls: [
~r/Claper\.Polls\.?/, ~r/Claper\.Polls\.?/,
~r/ClaperWeb\.Poll\.?/, ~r/ClaperWeb\.Poll\.?/
], ],
"Posts": [ Posts: [
~r/Claper\.Posts\.?/, ~r/Claper\.Posts\.?/,
~r/ClaperWeb\.Post\.?/, ~r/ClaperWeb\.Post\.?/
] ]
] ]
] ]

View File

@@ -107,8 +107,7 @@ defmodule Claper.AccountsTest do
end end
test "validates email", %{user: user} do test "validates email", %{user: user} do
{:error, changeset} = {:error, changeset} = Accounts.apply_user_email(user, %{email: "not valid"})
Accounts.apply_user_email(user, %{email: "not valid"})
assert %{email: ["must have the @ sign and no spaces"]} = errors_on(changeset) assert %{email: ["must have the @ sign and no spaces"]} = errors_on(changeset)
end end
@@ -116,8 +115,7 @@ defmodule Claper.AccountsTest do
test "validates maximum value for email for security", %{user: user} do test "validates maximum value for email for security", %{user: user} do
too_long = String.duplicate("db", 100) too_long = String.duplicate("db", 100)
{:error, changeset} = {:error, changeset} = Accounts.apply_user_email(user, %{email: too_long})
Accounts.apply_user_email(user, %{email: too_long})
assert "should be at most 160 character(s)" in errors_on(changeset).email assert "should be at most 160 character(s)" in errors_on(changeset).email
end end
@@ -125,8 +123,7 @@ defmodule Claper.AccountsTest do
test "validates email uniqueness", %{user: user} do test "validates email uniqueness", %{user: user} do
%{email: email} = user_fixture() %{email: email} = user_fixture()
{:error, changeset} = {:error, changeset} = Accounts.apply_user_email(user, %{email: email})
Accounts.apply_user_email(user, %{email: email})
assert "has already been taken" in errors_on(changeset).email assert "has already been taken" in errors_on(changeset).email
end end
@@ -305,5 +302,4 @@ defmodule Claper.AccountsTest do
assert Repo.get_by(UserToken, user_id: user.id) assert Repo.get_by(UserToken, user_id: user.id)
end end
end end
end end

View File

@@ -2,10 +2,9 @@ defmodule Claper.EventsTest do
use Claper.DataCase use Claper.DataCase
alias Claper.Events alias Claper.Events
import Claper.{EventsFixtures,AccountsFixtures} import Claper.{EventsFixtures, AccountsFixtures}
describe "events" do describe "events" do
alias Claper.Events.Event alias Claper.Events.Event
@invalid_attrs %{name: nil, code: nil} @invalid_attrs %{name: nil, code: nil}
@@ -32,12 +31,22 @@ defmodule Claper.EventsTest do
test "get_user_event!/3 with invalid user raises exception" do test "get_user_event!/3 with invalid user raises exception" do
event = event_fixture() event = event_fixture()
event2 = event_fixture() event2 = event_fixture()
assert_raise Ecto.NoResultsError, fn -> Events.get_user_event!(event.user_id, event2.uuid) == event end
assert_raise Ecto.NoResultsError, fn ->
Events.get_user_event!(event.user_id, event2.uuid) == event
end
end end
test "create_event/1 with valid data creates a event" do test "create_event/1 with valid data creates a event" do
user = user_fixture() user = user_fixture()
valid_attrs = %{name: "some name", code: "code", user_id: user.id, started_at: NaiveDateTime.utc_now, expired_at: NaiveDateTime.add(NaiveDateTime.utc_now, 7200, :second)}
valid_attrs = %{
name: "some name",
code: "code",
user_id: user.id,
started_at: NaiveDateTime.utc_now(),
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now(), 7200, :second)
}
assert {:ok, %Event{} = event} = Events.create_event(valid_attrs) assert {:ok, %Event{} = event} = Events.create_event(valid_attrs)
assert event.name == "some name" assert event.name == "some name"

View File

@@ -6,37 +6,46 @@ defmodule Claper.PollsTest do
describe "polls" do describe "polls" do
alias Claper.Polls.Poll alias Claper.Polls.Poll
import Claper.{PollsFixtures,PresentationsFixtures} import Claper.{PollsFixtures, PresentationsFixtures}
@invalid_attrs %{title: nil} @invalid_attrs %{title: nil}
test "list_polls/1 returns all polls from a presentation" do test "list_polls/1 returns all polls from a presentation" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
poll = poll_fixture(%{presentation_file_id: presentation_file.id }) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
assert Polls.list_polls(presentation_file.id) == [poll] assert Polls.list_polls(presentation_file.id) == [poll]
end end
test "list_polls_at_position/2 returns all polls from a presentation at a given position" do test "list_polls_at_position/2 returns all polls from a presentation at a given position" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
poll = poll_fixture(%{presentation_file_id: presentation_file.id, position: 5 }) poll = poll_fixture(%{presentation_file_id: presentation_file.id, position: 5})
assert Polls.list_polls_at_position(presentation_file.id, 5) == [poll] assert Polls.list_polls_at_position(presentation_file.id, 5) == [poll]
end end
test "get_poll!/1 returns the poll with given id" do test "get_poll!/1 returns the poll with given id" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
poll = poll_fixture(%{presentation_file_id: presentation_file.id }) |> Claper.Polls.set_percentages()
poll =
poll_fixture(%{presentation_file_id: presentation_file.id})
|> Claper.Polls.set_percentages()
assert Polls.get_poll!(poll.id) == poll assert Polls.get_poll!(poll.id) == poll
end end
test "create_poll/1 with valid data creates a poll" do test "create_poll/1 with valid data creates a poll" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
valid_attrs = %{title: "some title", presentation_file_id: presentation_file.id, position: 0, poll_opts: [
valid_attrs = %{
title: "some title",
presentation_file_id: presentation_file.id,
position: 0,
poll_opts: [
%{content: "some option 1", vote_count: 0}, %{content: "some option 1", vote_count: 0},
%{content: "some option 2", vote_count: 0}, %{content: "some option 2", vote_count: 0}
]} ]
}
assert {:ok, %Poll{} = poll} = Polls.create_poll(valid_attrs) assert {:ok, %Poll{} = poll} = Polls.create_poll(valid_attrs)
assert poll.title == "some title" assert poll.title == "some title"
@@ -51,14 +60,19 @@ defmodule Claper.PollsTest do
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
update_attrs = %{title: "some updated title"} update_attrs = %{title: "some updated title"}
assert {:ok, %Poll{} = poll} = Polls.update_poll(presentation_file.event_id, poll, update_attrs) assert {:ok, %Poll{} = poll} =
Polls.update_poll(presentation_file.event_id, poll, update_attrs)
assert poll.title == "some updated title" assert poll.title == "some updated title"
end end
test "update_poll/3 with invalid data returns error changeset" do test "update_poll/3 with invalid data returns error changeset" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
assert {:error, %Ecto.Changeset{}} = Polls.update_poll(presentation_file.event_id, poll, @invalid_attrs)
assert {:error, %Ecto.Changeset{}} =
Polls.update_poll(presentation_file.event_id, poll, @invalid_attrs)
assert poll |> Claper.Polls.set_percentages() == Polls.get_poll!(poll.id) assert poll |> Claper.Polls.set_percentages() == Polls.get_poll!(poll.id)
end end
@@ -78,15 +92,15 @@ defmodule Claper.PollsTest do
end end
describe "poll_opts" do describe "poll_opts" do
import Claper.{PollsFixtures, PresentationsFixtures}
import Claper.{PollsFixtures,PresentationsFixtures}
test "add_poll_opt/1 returns poll changeset plus the added poll_opt" do test "add_poll_opt/1 returns poll changeset plus the added poll_opt" do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
poll_changeset = poll |> Polls.change_poll() poll_changeset = poll |> Polls.change_poll()
assert Ecto.Changeset.get_field(Polls.add_poll_opt(poll_changeset), :poll_opts) |> Enum.count == 3 assert Ecto.Changeset.get_field(Polls.add_poll_opt(poll_changeset), :poll_opts)
|> Enum.count() == 3
end end
test "remove_poll_opt/2 returns poll changeset minus the removed poll_opt" do test "remove_poll_opt/2 returns poll changeset minus the removed poll_opt" do
@@ -94,13 +108,16 @@ defmodule Claper.PollsTest do
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
poll_changeset = poll |> Polls.change_poll() poll_changeset = poll |> Polls.change_poll()
assert Ecto.Changeset.get_field(Polls.remove_poll_opt(poll_changeset, Enum.at(poll.poll_opts, 0)), :poll_opts) |> Enum.count == 1 assert Ecto.Changeset.get_field(
Polls.remove_poll_opt(poll_changeset, Enum.at(poll.poll_opts, 0)),
:poll_opts
)
|> Enum.count() == 1
end end
end end
describe "poll_votes" do describe "poll_votes" do
import Claper.{PollsFixtures, PresentationsFixtures}
import Claper.{PollsFixtures,PresentationsFixtures}
test "get_poll_vote/2 returns the poll_vote with given id and user id" do test "get_poll_vote/2 returns the poll_vote with given id and user id" do
poll_vote = poll_vote_fixture() poll_vote = poll_vote_fixture()
@@ -112,8 +129,13 @@ defmodule Claper.PollsTest do
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
[poll_opt | _] = poll.poll_opts [poll_opt | _] = poll.poll_opts
assert {:ok, %Polls.Poll{}} =
assert {:ok, %Polls.Poll{}} = Polls.vote(presentation_file.event.user_id, presentation_file.event_id, poll_opt, poll.id) Polls.vote(
presentation_file.event.user_id,
presentation_file.event_id,
poll_opt,
poll.id
)
end end
end end
end end

View File

@@ -8,7 +8,6 @@ defmodule Claper.PostsTest do
alias Claper.Posts.Post alias Claper.Posts.Post
describe "posts" do describe "posts" do
@invalid_attrs %{body: "a"} @invalid_attrs %{body: "a"}
test "list_posts/0 returns all posts from an event" do test "list_posts/0 returns all posts from an event" do
@@ -55,7 +54,6 @@ defmodule Claper.PostsTest do
end end
end end
describe "reactions" do describe "reactions" do
alias Claper.Posts.Reaction alias Claper.Posts.Reaction
@@ -86,7 +84,9 @@ defmodule Claper.PostsTest do
post = post_fixture() post = post_fixture()
reaction = reaction_fixture(%{post: post, user_id: post.user_id}) reaction = reaction_fixture(%{post: post, user_id: post.user_id})
assert {:ok, %Post{}} = Posts.delete_reaction(%{user_id: post.user_id, post: post, icon: "some icon"}) assert {:ok, %Post{}} =
Posts.delete_reaction(%{user_id: post.user_id, post: post, icon: "some icon"})
assert_raise Ecto.NoResultsError, fn -> Posts.get_reaction!(reaction.id) end assert_raise Ecto.NoResultsError, fn -> Posts.get_reaction!(reaction.id) end
end end
end end

View File

@@ -15,13 +15,17 @@ defmodule Claper.PresentationsTest do
test "get_presentation_file_by_hash!/2 returns the presentation_file with given hash" do test "get_presentation_file_by_hash!/2 returns the presentation_file with given hash" do
presentation_file = presentation_file_fixture(%{}, [:event]) presentation_file = presentation_file_fixture(%{}, [:event])
assert Presentations.get_presentation_file_by_hash!(presentation_file.hash) == presentation_file
assert Presentations.get_presentation_file_by_hash!(presentation_file.hash) ==
presentation_file
end end
test "create_presentation_file/1 with valid data creates a presentation_file" do test "create_presentation_file/1 with valid data creates a presentation_file" do
valid_attrs = %{hash: "1234", length: 42} valid_attrs = %{hash: "1234", length: 42}
assert {:ok, %PresentationFile{} = presentation_file} = Presentations.create_presentation_file(valid_attrs) assert {:ok, %PresentationFile{} = presentation_file} =
Presentations.create_presentation_file(valid_attrs)
assert presentation_file.hash == "1234" assert presentation_file.hash == "1234"
assert presentation_file.length == 42 assert presentation_file.length == 42
end end
@@ -30,7 +34,9 @@ defmodule Claper.PresentationsTest do
presentation_file = presentation_file_fixture() presentation_file = presentation_file_fixture()
update_attrs = %{hash: "4567", length: 43} update_attrs = %{hash: "4567", length: 43}
assert {:ok, %PresentationFile{} = presentation_file} = Presentations.update_presentation_file(presentation_file, update_attrs) assert {:ok, %PresentationFile{} = presentation_file} =
Presentations.update_presentation_file(presentation_file, update_attrs)
assert presentation_file.hash == "4567" assert presentation_file.hash == "4567"
assert presentation_file.length == 43 assert presentation_file.length == 43
end end
@@ -51,7 +57,8 @@ defmodule Claper.PresentationsTest do
presentation_state = presentation_state_fixture() presentation_state = presentation_state_fixture()
update_attrs = %{} update_attrs = %{}
assert {:ok, %PresentationState{}} = Presentations.update_presentation_state(presentation_state, update_attrs) assert {:ok, %PresentationState{}} =
Presentations.update_presentation_state(presentation_state, update_attrs)
end end
end end
end end

View File

@@ -25,7 +25,9 @@ defmodule ClaperWeb.EventLiveTest do
test "updates event in listing", %{conn: conn, presentation_file: presentation_file} do test "updates event in listing", %{conn: conn, presentation_file: presentation_file} do
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index)) {:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
assert index_live |> element("#event-#{presentation_file.event.uuid} a", "Edit") |> render_click() =~ assert index_live
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|> render_click() =~
"Edit" "Edit"
assert_patch(index_live, Routes.event_index_path(conn, :edit, presentation_file.event.uuid)) assert_patch(index_live, Routes.event_index_path(conn, :edit, presentation_file.event.uuid))
@@ -43,15 +45,19 @@ defmodule ClaperWeb.EventLiveTest do
test "deletes event in listing", %{conn: conn, presentation_file: presentation_file} do test "deletes event in listing", %{conn: conn, presentation_file: presentation_file} do
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index)) {:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
assert index_live |> element("#event-#{presentation_file.event.uuid} a", "Edit") |> render_click() =~ assert index_live
|> element("#event-#{presentation_file.event.uuid} a", "Edit")
|> render_click() =~
"Edit" "Edit"
{:ok, conn} = index_live |> element(~s{a[phx-value-id=#{presentation_file.event.uuid}]}) |> render_click() {:ok, conn} =
index_live
|> element(~s{a[phx-value-id=#{presentation_file.event.uuid}]})
|> render_click()
|> follow_redirect(conn, Routes.event_index_path(conn, :index)) |> follow_redirect(conn, Routes.event_index_path(conn, :index))
{:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index)) {:ok, index_live, _html} = live(conn, Routes.event_index_path(conn, :index))
refute has_element?(index_live, "#event-#{presentation_file.event.uuid}") refute has_element?(index_live, "#event-#{presentation_file.event.uuid}")
end end
end end
@@ -60,12 +66,11 @@ defmodule ClaperWeb.EventLiveTest do
setup [:register_and_log_in_user, :create_event] setup [:register_and_log_in_user, :create_event]
test "displays event", %{conn: conn, presentation_file: presentation_file} do test "displays event", %{conn: conn, presentation_file: presentation_file} do
{:ok, _show_live, html} =
{:ok, _show_live, html} = live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code)) live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
assert html =~ "Be the first to react" assert html =~ "Be the first to react"
assert html =~ presentation_file.event.name assert html =~ presentation_file.event.name
end end
end end
end end

View File

@@ -2,7 +2,7 @@ defmodule ClaperWeb.PostLiveTest do
use ClaperWeb.ConnCase use ClaperWeb.ConnCase
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
import Claper.{PresentationsFixtures,PostsFixtures} import Claper.{PresentationsFixtures, PostsFixtures}
defp create_event(params) do defp create_event(params) do
presentation_file = presentation_file_fixture(%{user: params.user}, [:event]) presentation_file = presentation_file_fixture(%{user: params.user}, [:event])
@@ -15,10 +15,10 @@ defmodule ClaperWeb.PostLiveTest do
setup [:register_and_log_in_user, :create_event] setup [:register_and_log_in_user, :create_event]
test "list posts", %{conn: conn, presentation_file: presentation_file} do test "list posts", %{conn: conn, presentation_file: presentation_file} do
{:ok, _index_live, html} = live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code)) {:ok, _index_live, html} =
live(conn, Routes.event_show_path(conn, :show, presentation_file.event.code))
assert html =~ "some body" assert html =~ "some body"
end end
end end
end end

View File

@@ -62,6 +62,5 @@ defmodule ClaperWeb.ConnCase do
|> Phoenix.ConnTest.init_test_session(%{}) |> Phoenix.ConnTest.init_test_session(%{})
|> Plug.Conn.put_session(:current_user, user) |> Plug.Conn.put_session(:current_user, user)
|> Plug.Conn.put_session(:user_token, token) |> Plug.Conn.put_session(:user_token, token)
end end
end end

View File

@@ -11,7 +11,7 @@ defmodule Claper.AccountsFixtures do
Enum.into(attrs, %{ Enum.into(attrs, %{
email: unique_user_email(), email: unique_user_email(),
password: valid_user_password(), password: valid_user_password(),
confirmed_at: NaiveDateTime.utc_now(), confirmed_at: NaiveDateTime.utc_now()
}) })
end end

View File

@@ -13,6 +13,7 @@ defmodule Claper.EventsFixtures do
""" """
def event_fixture(attrs \\ %{}, preload \\ []) do def event_fixture(attrs \\ %{}, preload \\ []) do
assoc = %{user: attrs[:user] || user_fixture()} assoc = %{user: attrs[:user] || user_fixture()}
{:ok, event} = {:ok, event} =
attrs attrs
|> Enum.into(%{ |> Enum.into(%{
@@ -20,12 +21,12 @@ defmodule Claper.EventsFixtures do
code: "#{Enum.random(1000..2000)}", code: "#{Enum.random(1000..2000)}",
uuid: Ecto.UUID.generate(), uuid: Ecto.UUID.generate(),
user_id: assoc.user.id, user_id: assoc.user.id,
started_at: NaiveDateTime.utc_now, started_at: NaiveDateTime.utc_now(),
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now, 7200, :second) # add 2 hours # add 2 hours
expired_at: NaiveDateTime.add(NaiveDateTime.utc_now(), 7200, :second)
}) })
|> Claper.Events.create_event() |> Claper.Events.create_event()
Claper.UtilFixture.merge_preload(event, preload, assoc) Claper.UtilFixture.merge_preload(event, preload, assoc)
end end
end end

View File

@@ -4,7 +4,7 @@ defmodule Claper.PollsFixtures do
entities via the `Claper.Polls` context. entities via the `Claper.Polls` context.
""" """
import Claper.{AccountsFixtures,PresentationsFixtures} import Claper.{AccountsFixtures, PresentationsFixtures}
require Claper.UtilFixture require Claper.UtilFixture
@@ -20,13 +20,12 @@ defmodule Claper.PollsFixtures do
enabled: true, enabled: true,
poll_opts: [ poll_opts: [
%{content: "some option 1", vote_count: 0}, %{content: "some option 1", vote_count: 0},
%{content: "some option 2", vote_count: 0}, %{content: "some option 2", vote_count: 0}
] ]
}) })
|> Claper.Polls.create_poll() |> Claper.Polls.create_poll()
Claper.UtilFixture.merge_preload(poll, preload, %{}) Claper.UtilFixture.merge_preload(poll, preload, %{})
end end
@doc """ @doc """
@@ -37,6 +36,7 @@ defmodule Claper.PollsFixtures do
poll = poll_fixture(%{presentation_file_id: presentation_file.id}) poll = poll_fixture(%{presentation_file_id: presentation_file.id})
[poll_opt | _] = poll.poll_opts [poll_opt | _] = poll.poll_opts
assoc = %{poll: poll} assoc = %{poll: poll}
{:ok, poll_vote} = {:ok, poll_vote} =
attrs attrs
|> Enum.into(%{ |> Enum.into(%{

View File

@@ -15,20 +15,23 @@ defmodule Claper.PostsFixtures do
user = attrs[:user] || user_fixture() user = attrs[:user] || user_fixture()
event = attrs[:event] || event_fixture() event = attrs[:event] || event_fixture()
assoc = %{user: user, event: event} assoc = %{user: user, event: event}
{:ok, post} = {:ok, post} =
Claper.Posts.create_post(assoc.event, attrs Claper.Posts.create_post(
assoc.event,
attrs
|> Enum.into(%{ |> Enum.into(%{
body: "some body", body: "some body",
like_count: 42, like_count: 42,
position: 0, position: 0,
uuid: Ecto.UUID.generate(), uuid: Ecto.UUID.generate(),
user_id: assoc.user.id user_id: assoc.user.id
})) })
)
Claper.UtilFixture.merge_preload(post, preload, assoc) Claper.UtilFixture.merge_preload(post, preload, assoc)
end end
@doc """ @doc """
Generate a reaction. Generate a reaction.
""" """

View File

@@ -13,6 +13,7 @@ defmodule Claper.PresentationsFixtures do
""" """
def presentation_file_fixture(attrs \\ %{}, preload \\ []) do def presentation_file_fixture(attrs \\ %{}, preload \\ []) do
assoc = %{event: attrs[:event] || event_fixture(attrs)} assoc = %{event: attrs[:event] || event_fixture(attrs)}
{:ok, presentation_file} = {:ok, presentation_file} =
attrs attrs
|> Enum.into(%{ |> Enum.into(%{
@@ -31,6 +32,7 @@ defmodule Claper.PresentationsFixtures do
""" """
def presentation_state_fixture(attrs \\ %{}, preload \\ []) do def presentation_state_fixture(attrs \\ %{}, preload \\ []) do
assoc = %{presentation_file: attrs[:presentation_file] || presentation_file_fixture()} assoc = %{presentation_file: attrs[:presentation_file] || presentation_file_fixture()}
{:ok, presentation_state} = {:ok, presentation_state} =
attrs attrs
|> Enum.into(%{ |> Enum.into(%{

View File

@@ -1,8 +1,10 @@
defmodule Claper.UtilFixture do defmodule Claper.UtilFixture do
defmacro merge_preload(origin, preload, assoc) do defmacro merge_preload(origin, preload, assoc) do
quote do quote do
unquote(origin) |> unquote(origin)
Map.merge(for p <- unquote(preload), unquote(assoc)[p], into: %{}, do: {p, unquote(assoc)[p]}) |> Map.merge(
for p <- unquote(preload), unquote(assoc)[p], into: %{}, do: {p, unquote(assoc)[p]}
)
end end
end end
end end