mix credo warnings in Mobilizon context

This commit is contained in:
miffigriffi 2019-09-18 00:37:31 +02:00
parent eaff073cd2
commit 64f42d412b
3 changed files with 14 additions and 6 deletions

View File

@ -115,7 +115,9 @@ defmodule Mobilizon.Actors do
"""
@spec get_actor_by_name(String.t(), atom | nil) :: Actor.t() | nil
def get_actor_by_name(name, type \\ nil) do
from(a in Actor)
query = from(a in Actor)
query
|> filter_by_type(type)
|> filter_by_name(String.split(name, "@"))
|> Repo.one()
@ -126,7 +128,9 @@ defmodule Mobilizon.Actors do
"""
@spec get_local_actor_by_name(String.t()) :: Actor.t() | nil
def get_local_actor_by_name(name) do
from(a in Actor)
query = from(a in Actor)
query
|> filter_by_name([name])
|> Repo.one()
end

View File

@ -293,7 +293,9 @@ defmodule Mobilizon.Events do
is_unlisted \\ false,
is_future \\ true
) do
from(e in Event, preload: [:organizer_actor, :participants])
query = from(e in Event, preload: [:organizer_actor, :participants])
query
|> Page.paginate(page, limit)
|> sort(sort, direction)
|> filter_future_events(is_future)
@ -779,8 +781,10 @@ defmodule Mobilizon.Events do
@spec get_comment_from_url_with_preload(String.t()) ::
{:ok, Comment.t()} | {:error, :comment_not_found}
def get_comment_from_url_with_preload(url) do
query = from(c in Comment, where: c.url == ^url)
comment =
from(c in Comment, where: c.url == ^url)
query
|> preload_for_comment()
|> Repo.one()

View File

@ -419,7 +419,7 @@ defmodule Mobilizon.EventsTest do
test "list_sessions_for_event/1 returns sessions for an event" do
event = insert(:event)
session = insert(:session, event: event)
assert Events.list_sessions_for_event(event) |> Enum.map(& &1.id) == [session.id]
assert event |> Events.list_sessions_for_event() |> Enum.map(& &1.id) == [session.id]
end
test "get_session!/1 returns the session with given id" do
@ -491,7 +491,7 @@ defmodule Mobilizon.EventsTest do
event = insert(:event)
track = insert(:track, event: event)
session = insert(:session, track: track, event: event)
assert Events.list_sessions_for_track(track) |> Enum.map(& &1.id) == [session.id]
assert track |> Events.list_sessions_for_track() |> Enum.map(& &1.id) == [session.id]
end
test "get_track!/1 returns the track with given id" do