From 1217361b6ccf6a45796f74caa14a460de43de3fc Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 14 Jan 2018 17:56:50 +0100 Subject: [PATCH] fix some code style and add checks to ci Signed-off-by: Thomas Citharel --- .gitignore | 2 ++ .gitlab-ci.yml | 3 ++- config/config.exs | 2 +- config/dogma.exs | 17 ++++++++++++ lib/eventos.ex | 8 +++--- lib/eventos/accounts/account.ex | 3 +++ lib/eventos/accounts/accounts.ex | 27 ++++++------------- lib/eventos/accounts/user.ex | 3 +++ lib/eventos/application.ex | 3 +++ lib/eventos/events/category.ex | 3 +++ lib/eventos/events/event.ex | 22 ++++++--------- lib/eventos/events/events.ex | 1 - lib/eventos/events/participant.ex | 3 +++ lib/eventos/events/request.ex | 3 +++ lib/eventos/events/session.ex | 3 +++ lib/eventos/events/tag.ex | 22 ++++++--------- lib/eventos/events/track.ex | 3 +++ lib/eventos/groups/group.ex | 22 ++++++--------- lib/eventos/groups/member.ex | 3 +++ lib/eventos/groups/request.ex | 3 +++ lib/eventos/postgrex_types.ex | 2 +- lib/eventos/repo.ex | 3 +++ lib/eventos/slug.ex | 16 +++++++++++ lib/eventos_web/auth_error_handler.ex | 5 +++- lib/eventos_web/auth_pipeline.ex | 5 +++- lib/eventos_web/channels/user_socket.ex | 7 +++-- .../controllers/account_controller.ex | 4 ++- .../controllers/category_controller.ex | 3 +++ .../controllers/event_controller.ex | 3 +++ .../controllers/group_controller.ex | 3 +++ .../controllers/page_controller.ex | 3 +++ .../controllers/session_controller.ex | 3 +++ lib/eventos_web/controllers/tag_controller.ex | 3 +++ .../controllers/track_controller.ex | 3 +++ .../controllers/user_controller.ex | 13 +++++---- .../controllers/user_session_controller.ex | 8 +++--- lib/eventos_web/endpoint.ex | 3 +++ lib/eventos_web/guardian.ex | 18 +++++-------- lib/eventos_web/router.ex | 3 +++ lib/eventos_web/views/account_view.ex | 3 +++ lib/eventos_web/views/category_view.ex | 3 +++ lib/eventos_web/views/changeset_view.ex | 3 +++ lib/eventos_web/views/error_view.ex | 3 +++ lib/eventos_web/views/event_view.ex | 3 +++ lib/eventos_web/views/group_view.ex | 3 +++ lib/eventos_web/views/member_view.ex | 3 +++ lib/eventos_web/views/page_view.ex | 3 +++ lib/eventos_web/views/participant_view.ex | 3 +++ lib/eventos_web/views/request_view.ex | 3 +++ lib/eventos_web/views/session_view.ex | 3 +++ lib/eventos_web/views/tag_view.ex | 3 +++ lib/eventos_web/views/track_view.ex | 3 +++ lib/eventos_web/views/user_session_view.ex | 3 +++ lib/eventos_web/views/user_view.ex | 3 +++ mix.exs | 8 +++++- mix.lock | 3 +++ test/eventos/accounts/accounts_test.exs | 4 +-- test/eventos/events/events_test.exs | 8 +++--- test/eventos/groups/groups_test.exs | 4 +-- .../controllers/account_controller_test.exs | 2 -- .../controllers/user_controller_test.exs | 3 ++- .../user_session_controller_test.exs | 1 + test/support/factory.ex | 7 +++-- test/test_helper.exs | 1 - 64 files changed, 242 insertions(+), 108 deletions(-) create mode 100644 config/dogma.exs create mode 100644 lib/eventos/slug.ex diff --git a/.gitignore b/.gitignore index d26faf840..caa3d786e 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ erl_crash.dump # secrets files as long as you replace their contents by environment # variables. /config/*.secret.exs + +/doc \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ebd51aa5..bdf9d8eff 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,5 +29,6 @@ before_script: mix: script: - - mix credo || true + - mix credo + - mix dogma - mix coveralls diff --git a/config/config.exs b/config/config.exs index 5b098d4d9..4cf6ba116 100644 --- a/config/config.exs +++ b/config/config.exs @@ -34,4 +34,4 @@ config :guardian, Guardian.DB, repo: Eventos.Repo, schema_name: "guardian_tokens", # default token_types: ["refresh_token"], # store all token types if not set - sweep_interval: 60 # default: 60 minutes \ No newline at end of file + sweep_interval: 60 # default: 60 minutes diff --git a/config/dogma.exs b/config/dogma.exs new file mode 100644 index 000000000..fd2dba779 --- /dev/null +++ b/config/dogma.exs @@ -0,0 +1,17 @@ +use Mix.Config +alias Dogma.Rule + +config :dogma, + + # Select a set of rules as a base + rule_set: Dogma.RuleSet.All, + + # Pick paths not to lint + exclude: [ + ~r(\Alib/vendor/), + ], + + # Override an existing rule configuration + override: [ + %Rule.LineLength{ enabled: false }, + ] diff --git a/lib/eventos.ex b/lib/eventos.ex index dc90b3c1e..9cc4de367 100644 --- a/lib/eventos.ex +++ b/lib/eventos.ex @@ -1,9 +1,9 @@ defmodule Eventos do @moduledoc """ - Eventos keeps the contexts that define your domain - and business logic. + Eventos is a decentralized and federated Meetup-like using [ActivityPub](http://activitypub.rocks/). - Contexts are also responsible for managing your data, regardless - if it comes from the database, an external API or others. + It consists of an API server build with [Elixir](http://elixir-lang.github.io/) and the [Phoenix Framework](https://hexdocs.pm/phoenix). + + Eventos relies on `Guardian` for auth and `Geo`/Postgis for geographical informations. """ end diff --git a/lib/eventos/accounts/account.ex b/lib/eventos/accounts/account.ex index 498364be7..85ce940bd 100644 --- a/lib/eventos/accounts/account.ex +++ b/lib/eventos/accounts/account.ex @@ -1,4 +1,7 @@ defmodule Eventos.Accounts.Account do + @moduledoc """ + Represents an account (local and remote users) + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Accounts.{Account, User} diff --git a/lib/eventos/accounts/accounts.ex b/lib/eventos/accounts/accounts.ex index 5bed1020c..07685e429 100644 --- a/lib/eventos/accounts/accounts.ex +++ b/lib/eventos/accounts/accounts.ex @@ -5,7 +5,6 @@ defmodule Eventos.Accounts do import Ecto.Query, warn: false alias Eventos.Repo - import Logger alias Eventos.Accounts.Account @@ -37,12 +36,12 @@ defmodule Eventos.Accounts do """ def get_account!(id) do - account = Repo.get!(Account, id) + Repo.get!(Account, id) end def get_account_with_everything!(id) do account = Repo.get!(Account, id) - |> Repo.preload :organized_events + Repo.preload(account, :organized_events) end @doc """ @@ -126,8 +125,8 @@ defmodule Eventos.Accounts do end def list_users_with_accounts do - Repo.all(User) - |> Repo.preload :account + users = Repo.all(User) + Repo.preload(users, :account) end @doc """ @@ -147,8 +146,8 @@ defmodule Eventos.Accounts do def get_user!(id), do: Repo.get!(User, id) def get_user_with_account!(id) do - Repo.get!(User, id) - |> Repo.preload :account + user = Repo.get!(User, id) + Repo.preload(user, :account) end @doc """ @@ -156,7 +155,7 @@ defmodule Eventos.Accounts do """ def find_by_email(email) do user = Repo.get_by(User, email: email) - |> Repo.preload :account + Repo.preload(user, :account) end @doc """ @@ -199,23 +198,13 @@ defmodule Eventos.Accounts do account_with_user = Ecto.Changeset.put_assoc(account, :user, user) try do - coucou = Eventos.Repo.insert!(account_with_user) + Eventos.Repo.insert!(account_with_user) user = find_by_email(email) {:ok, user} rescue e in Ecto.InvalidChangesetError -> - Logger.debug(inspect e) {:error, e.changeset.changes.user.errors} end - -# with {:ok, %Account{} = account} <- create_account(%{username: username, suspended: false, domain: nil, private_key: privkey, public_key: pubkey, uri: "h", url: "h"}) do -# case create_user(%{email: email, password: password, account: account}) do -# {:ok, %User{} = user } -> -# {:ok, user} -# {:error, %Ecto.Changeset{} = changeset} -> -# {:error, changeset} -# end -# end end diff --git a/lib/eventos/accounts/user.ex b/lib/eventos/accounts/user.ex index 35e74fb8c..aa294d6bb 100644 --- a/lib/eventos/accounts/user.ex +++ b/lib/eventos/accounts/user.ex @@ -1,4 +1,7 @@ defmodule Eventos.Accounts.User do + @moduledoc """ + Represents a local user + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Accounts.{Account, User} diff --git a/lib/eventos/application.ex b/lib/eventos/application.ex index 511ca178f..6dfadb8c0 100644 --- a/lib/eventos/application.ex +++ b/lib/eventos/application.ex @@ -1,4 +1,7 @@ defmodule Eventos.Application do + @moduledoc """ + The Eventos application + """ use Application # See https://hexdocs.pm/elixir/Application.html diff --git a/lib/eventos/events/category.ex b/lib/eventos/events/category.ex index e9692f97f..6b93f1879 100644 --- a/lib/eventos/events/category.ex +++ b/lib/eventos/events/category.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Category do + @moduledoc """ + Represents a category for events + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.Category diff --git a/lib/eventos/events/event.ex b/lib/eventos/events/event.ex index 471e13c9b..dea3a0d64 100644 --- a/lib/eventos/events/event.ex +++ b/lib/eventos/events/event.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Event.TitleSlug do + @moduledoc """ + Generates a slug for an event title + """ alias Eventos.Events.Event import Ecto.Query alias Eventos.Repo @@ -17,25 +20,16 @@ defmodule Eventos.Events.Event.TitleSlug do nil -> slug _event -> slug - |> increment_slug + |> Eventos.Slug.increment_slug() |> build_unique_slug(changeset) end end - - defp increment_slug(slug) do - case List.pop_at(String.split(slug, "-"), -1) do - {nil, _} -> - slug - {suffix, slug_parts} -> - case Integer.parse(suffix) do - {id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1) - :error -> slug <> "-1" - end - end - end end defmodule Eventos.Events.Event do + @moduledoc """ + Represents an event + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.{Event, Participant, Request, Tag, Session, Track} @@ -72,4 +66,4 @@ defmodule Eventos.Events.Event do |> TitleSlug.maybe_generate_slug() |> TitleSlug.unique_constraint() end -end \ No newline at end of file +end diff --git a/lib/eventos/events/events.ex b/lib/eventos/events/events.ex index 0281c4d16..20cdf23e3 100644 --- a/lib/eventos/events/events.ex +++ b/lib/eventos/events/events.ex @@ -7,7 +7,6 @@ defmodule Eventos.Events do alias Eventos.Repo alias Eventos.Events.Event - alias Eventos.Accounts.Account @doc """ Returns the list of events. diff --git a/lib/eventos/events/participant.ex b/lib/eventos/events/participant.ex index 9f88c404f..f1cfed17c 100644 --- a/lib/eventos/events/participant.ex +++ b/lib/eventos/events/participant.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Participant do + @moduledoc """ + Represents a participant, an account participating to an event + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.{Participant, Event} diff --git a/lib/eventos/events/request.ex b/lib/eventos/events/request.ex index ee499c5fb..1bfd77a95 100644 --- a/lib/eventos/events/request.ex +++ b/lib/eventos/events/request.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Request do + @moduledoc """ + Represents an account request to join an event + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.{Request, Event} diff --git a/lib/eventos/events/session.ex b/lib/eventos/events/session.ex index 33af3c013..c8853409e 100644 --- a/lib/eventos/events/session.ex +++ b/lib/eventos/events/session.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Session do + @moduledoc """ + Represents a session for an event (such as a talk at a conference) + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.{Session, Event, Track} diff --git a/lib/eventos/events/tag.ex b/lib/eventos/events/tag.ex index 04218abd0..8f5410138 100644 --- a/lib/eventos/events/tag.ex +++ b/lib/eventos/events/tag.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Tag.TitleSlug do + @moduledoc """ + Generates slugs for tags + """ alias Eventos.Events.Tag import Ecto.Query alias Eventos.Repo @@ -17,25 +20,16 @@ defmodule Eventos.Events.Tag.TitleSlug do nil -> slug _story -> slug - |> increment_slug + |> Eventos.Slug.increment_slug() |> build_unique_slug(changeset) end end - - defp increment_slug(slug) do - case List.pop_at(String.split(slug, "-"), -1) do - {nil, _} -> - slug - {suffix, slug_parts} -> - case Integer.parse(suffix) do - {id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1) - :error -> slug <> "-1" - end - end - end end defmodule Eventos.Events.Tag do + @moduledoc """ + Represents a tag for events + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.Tag @@ -56,4 +50,4 @@ defmodule Eventos.Events.Tag do |> TitleSlug.maybe_generate_slug() |> TitleSlug.unique_constraint() end -end \ No newline at end of file +end diff --git a/lib/eventos/events/track.ex b/lib/eventos/events/track.ex index 711314aa6..9beaf94d6 100644 --- a/lib/eventos/events/track.ex +++ b/lib/eventos/events/track.ex @@ -1,4 +1,7 @@ defmodule Eventos.Events.Track do + @moduledoc """ + Represents a track for an event (such as a theme) having multiple sessions + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Events.{Track, Event, Session} diff --git a/lib/eventos/groups/group.ex b/lib/eventos/groups/group.ex index 67be9f61d..a11256f03 100644 --- a/lib/eventos/groups/group.ex +++ b/lib/eventos/groups/group.ex @@ -1,4 +1,7 @@ defmodule Eventos.Groups.Group.TitleSlug do + @moduledoc """ + Slug generation for groups + """ alias Eventos.Groups.Group import Ecto.Query alias Eventos.Repo @@ -17,25 +20,16 @@ defmodule Eventos.Groups.Group.TitleSlug do nil -> slug _story -> slug - |> increment_slug + |> Eventos.Slug.increment_slug() |> build_unique_slug(changeset) end end - - defp increment_slug(slug) do - case List.pop_at(String.split(slug, "-"), -1) do - {nil, _} -> - slug - {suffix, slug_parts} -> - case Integer.parse(suffix) do - {id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1) - :error -> slug <> "-1" - end - end - end end defmodule Eventos.Groups.Group do + @moduledoc """ + Represents a group + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Groups.{Group, Member, Request} @@ -63,4 +57,4 @@ defmodule Eventos.Groups.Group do |> TitleSlug.maybe_generate_slug() |> TitleSlug.unique_constraint() end -end \ No newline at end of file +end diff --git a/lib/eventos/groups/member.ex b/lib/eventos/groups/member.ex index a96a68439..f9ec58cbd 100644 --- a/lib/eventos/groups/member.ex +++ b/lib/eventos/groups/member.ex @@ -1,4 +1,7 @@ defmodule Eventos.Groups.Member do + @moduledoc """ + Represents the membership of an account to a group + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Groups.{Member, Group} diff --git a/lib/eventos/groups/request.ex b/lib/eventos/groups/request.ex index f8ea04eb9..b4cf994a6 100644 --- a/lib/eventos/groups/request.ex +++ b/lib/eventos/groups/request.ex @@ -1,4 +1,7 @@ defmodule Eventos.Groups.Request do + @moduledoc """ + Represents a group request, when an user wants to be member of a group + """ use Ecto.Schema import Ecto.Changeset alias Eventos.Groups.Request diff --git a/lib/eventos/postgrex_types.ex b/lib/eventos/postgrex_types.ex index 40136e0ab..9b3f37b50 100644 --- a/lib/eventos/postgrex_types.ex +++ b/lib/eventos/postgrex_types.ex @@ -1,3 +1,3 @@ Postgrex.Types.define(Eventos.PostgresTypes, [Geo.PostGIS.Extension] ++ Ecto.Adapters.Postgres.extensions(), - json: Poison) \ No newline at end of file + json: Poison) diff --git a/lib/eventos/repo.ex b/lib/eventos/repo.ex index ed18b2077..13b5255e3 100644 --- a/lib/eventos/repo.ex +++ b/lib/eventos/repo.ex @@ -1,4 +1,7 @@ defmodule Eventos.Repo do + @moduledoc """ + Eventos Repo + """ use Ecto.Repo, otp_app: :eventos @doc """ diff --git a/lib/eventos/slug.ex b/lib/eventos/slug.ex new file mode 100644 index 000000000..0ffd5fad6 --- /dev/null +++ b/lib/eventos/slug.ex @@ -0,0 +1,16 @@ +defmodule Eventos.Slug do + @moduledoc """ + Common functions for slug generation + """ + def increment_slug(slug) do + case List.pop_at(String.split(slug, "-"), -1) do + {nil, _} -> + slug + {suffix, slug_parts} -> + case Integer.parse(suffix) do + {id, _} -> Enum.join(slug_parts, "-") <> "-" <> Integer.to_string(id + 1) + :error -> slug <> "-1" + end + end + end +end diff --git a/lib/eventos_web/auth_error_handler.ex b/lib/eventos_web/auth_error_handler.ex index 27de010de..f819b8e47 100644 --- a/lib/eventos_web/auth_error_handler.ex +++ b/lib/eventos_web/auth_error_handler.ex @@ -1,8 +1,11 @@ defmodule EventosWeb.AuthErrorHandler do + @moduledoc """ + In case we have an auth error + """ import Plug.Conn def auth_error(conn, {type, _reason}, _opts) do body = Poison.encode!(%{message: to_string(type)}) send_resp(conn, 401, body) end -end \ No newline at end of file +end diff --git a/lib/eventos_web/auth_pipeline.ex b/lib/eventos_web/auth_pipeline.ex index 3f25f12b3..dccdc5c21 100644 --- a/lib/eventos_web/auth_pipeline.ex +++ b/lib/eventos_web/auth_pipeline.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.AuthPipeline do + @moduledoc """ + Handles the app sessions + """ use Guardian.Plug.Pipeline, otp_app: :eventos, module: EventosWeb.Guardian, @@ -8,4 +11,4 @@ defmodule EventosWeb.AuthPipeline do plug Guardian.Plug.EnsureAuthenticated plug Guardian.Plug.LoadResource, ensure: true -end \ No newline at end of file +end diff --git a/lib/eventos_web/channels/user_socket.ex b/lib/eventos_web/channels/user_socket.ex index 9292adb44..89099bd91 100644 --- a/lib/eventos_web/channels/user_socket.ex +++ b/lib/eventos_web/channels/user_socket.ex @@ -1,10 +1,13 @@ defmodule EventosWeb.UserSocket do + @moduledoc """ + Channel for User + """ use Phoenix.Socket - ## Channels + # Channels # channel "room:*", EventosWeb.RoomChannel - ## Transports + # Transports transport :websocket, Phoenix.Transports.WebSocket # transport :longpoll, Phoenix.Transports.LongPoll diff --git a/lib/eventos_web/controllers/account_controller.ex b/lib/eventos_web/controllers/account_controller.ex index a1a492dea..420c48bc9 100644 --- a/lib/eventos_web/controllers/account_controller.ex +++ b/lib/eventos_web/controllers/account_controller.ex @@ -1,9 +1,11 @@ defmodule EventosWeb.AccountController do + @moduledoc """ + Controller for Accounts + """ use EventosWeb, :controller alias Eventos.Accounts alias Eventos.Accounts.Account - import Logger action_fallback EventosWeb.FallbackController diff --git a/lib/eventos_web/controllers/category_controller.ex b/lib/eventos_web/controllers/category_controller.ex index fe6f181af..a32cad6bb 100644 --- a/lib/eventos_web/controllers/category_controller.ex +++ b/lib/eventos_web/controllers/category_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.CategoryController do + @moduledoc """ + Controller for Categories + """ use EventosWeb, :controller alias Eventos.Events diff --git a/lib/eventos_web/controllers/event_controller.ex b/lib/eventos_web/controllers/event_controller.ex index 22541c352..a8bf177e7 100644 --- a/lib/eventos_web/controllers/event_controller.ex +++ b/lib/eventos_web/controllers/event_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.EventController do + @moduledoc """ + Controller for Events + """ use EventosWeb, :controller alias Eventos.Events diff --git a/lib/eventos_web/controllers/group_controller.ex b/lib/eventos_web/controllers/group_controller.ex index e6986c17c..fbaf8c61e 100644 --- a/lib/eventos_web/controllers/group_controller.ex +++ b/lib/eventos_web/controllers/group_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.GroupController do + @moduledoc """ + Controller for Groups + """ use EventosWeb, :controller alias Eventos.Groups diff --git a/lib/eventos_web/controllers/page_controller.ex b/lib/eventos_web/controllers/page_controller.ex index dd6ce42d1..61b8f71ba 100644 --- a/lib/eventos_web/controllers/page_controller.ex +++ b/lib/eventos_web/controllers/page_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.PageController do + @moduledoc """ + Controller to load our webapp + """ use EventosWeb, :controller plug :put_layout, false diff --git a/lib/eventos_web/controllers/session_controller.ex b/lib/eventos_web/controllers/session_controller.ex index 31f1862ac..dcedd9917 100644 --- a/lib/eventos_web/controllers/session_controller.ex +++ b/lib/eventos_web/controllers/session_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.SessionController do + @moduledoc """ + Controller for (event) Sessions + """ use EventosWeb, :controller alias Eventos.Events diff --git a/lib/eventos_web/controllers/tag_controller.ex b/lib/eventos_web/controllers/tag_controller.ex index ec7ec0d76..ec35c12fe 100644 --- a/lib/eventos_web/controllers/tag_controller.ex +++ b/lib/eventos_web/controllers/tag_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.TagController do + @moduledoc """ + Controller for Tags + """ use EventosWeb, :controller alias Eventos.Events diff --git a/lib/eventos_web/controllers/track_controller.ex b/lib/eventos_web/controllers/track_controller.ex index fb5193e8e..99dc4145a 100644 --- a/lib/eventos_web/controllers/track_controller.ex +++ b/lib/eventos_web/controllers/track_controller.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.TrackController do + @moduledoc """ + Controller for Tracks + """ use EventosWeb, :controller alias Eventos.Events diff --git a/lib/eventos_web/controllers/user_controller.ex b/lib/eventos_web/controllers/user_controller.ex index c90a0af2b..a2982fb95 100644 --- a/lib/eventos_web/controllers/user_controller.ex +++ b/lib/eventos_web/controllers/user_controller.ex @@ -1,6 +1,8 @@ defmodule EventosWeb.UserController do + @moduledoc """ + Controller for Users + """ use EventosWeb, :controller - import Logger alias Eventos.Accounts alias Eventos.Accounts.User @@ -16,11 +18,10 @@ defmodule EventosWeb.UserController do def register(conn, %{"username" => username, "email" => email, "password" => password}) do case Accounts.register(%{email: email, password: password, username: username}) do {:ok, %User{} = user} -> - Logger.debug(inspect user) {:ok, token, _claims} = EventosWeb.Guardian.encode_and_sign(user) conn |> put_status(:created) - |> render "show_with_token.json", %{token: token, user: user} + |> render("show_with_token.json", %{token: token, user: user}) {:error, error} -> conn |> put_resp_content_type("application/json") @@ -30,12 +31,14 @@ defmodule EventosWeb.UserController do def show_current_account(conn, _params) do user = Guardian.Plug.current_resource(conn) - |> Repo.preload :account + user + |> Repo.preload(:account) render(conn, "show_simple.json", user: user) end defp handle_changeset_errors(errors) do - Enum.map(errors, fn {field, detail} -> + errors + |> Enum.map(fn {field, detail} -> "#{field} " <> render_detail(detail) end) |> Enum.join diff --git a/lib/eventos_web/controllers/user_session_controller.ex b/lib/eventos_web/controllers/user_session_controller.ex index dab1099c3..0858606a8 100644 --- a/lib/eventos_web/controllers/user_session_controller.ex +++ b/lib/eventos_web/controllers/user_session_controller.ex @@ -1,8 +1,10 @@ defmodule EventosWeb.UserSessionController do + @moduledoc """ + Controller for user sessions + """ use EventosWeb, :controller alias Eventos.Accounts.User alias Eventos.Accounts - import Logger def sign_in(conn, %{"email" => email, "password" => password}) do case Accounts.find_by_email(email) do @@ -22,7 +24,7 @@ defmodule EventosWeb.UserSessionController do def sign_out(conn, _params) do conn - |> Guardian.Plug.sign_out() + |> EventosWeb.Guardian.Plug.sign_out() |> send_resp(204, "") end -end \ No newline at end of file +end diff --git a/lib/eventos_web/endpoint.ex b/lib/eventos_web/endpoint.ex index 10ddcb270..82dcb859a 100644 --- a/lib/eventos_web/endpoint.ex +++ b/lib/eventos_web/endpoint.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.Endpoint do + @moduledoc """ + Endpoint for Eventos app + """ use Phoenix.Endpoint, otp_app: :eventos socket "/socket", EventosWeb.UserSocket diff --git a/lib/eventos_web/guardian.ex b/lib/eventos_web/guardian.ex index 805443762..dcb3840ee 100644 --- a/lib/eventos_web/guardian.ex +++ b/lib/eventos_web/guardian.ex @@ -1,15 +1,16 @@ defmodule EventosWeb.Guardian do + @moduledoc """ + Handles the JWT tokens encoding and decoding + """ use Guardian, otp_app: :eventos, permissions: %{ superuser: [:moderate, :super], user: [:base] } - import Logger - alias Eventos.Accounts - alias Eventos.Accounts.{Account, User} + alias Eventos.Accounts.User - def subject_for_token(user = %User{}, _claims) do + def subject_for_token(%User{} = user, _claims) do {:ok, "User:" <> to_string(user.id)} end @@ -19,8 +20,6 @@ defmodule EventosWeb.Guardian do def resource_from_claims(%{"sub" => "User:" <> uid_str}) do try do - Logger.debug("Inspecting resource token") - Logger.debug(inspect uid_str) case Integer.parse(uid_str) do {uid, ""} -> {:ok, Accounts.get_user_with_account!(uid)} @@ -32,9 +31,7 @@ defmodule EventosWeb.Guardian do end end - def resource_from_claims(claims) do - Logger.debug("Check bad resource") - Logger.debug(inspect claims) + def resource_from_claims(_) do {:error, :reason_for_error} end @@ -45,7 +42,6 @@ defmodule EventosWeb.Guardian do end def on_verify(claims, token, _options) do - Logger.debug(inspect claims) with {:ok, _} <- Guardian.DB.on_verify(claims, token) do {:ok, claims} end @@ -62,4 +58,4 @@ defmodule EventosWeb.Guardian do # |> encode_permissions_into_claims!(Keyword.get(opts, :permissions)) # {:ok, claims} # end -end \ No newline at end of file +end diff --git a/lib/eventos_web/router.ex b/lib/eventos_web/router.ex index 1532e0748..1760636c0 100644 --- a/lib/eventos_web/router.ex +++ b/lib/eventos_web/router.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.Router do + @moduledoc """ + Router for eventos app + """ use EventosWeb, :router pipeline :api do diff --git a/lib/eventos_web/views/account_view.ex b/lib/eventos_web/views/account_view.ex index 8c4ccbed4..c36373bd0 100644 --- a/lib/eventos_web/views/account_view.ex +++ b/lib/eventos_web/views/account_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.AccountView do + @moduledoc """ + View for Accounts + """ use EventosWeb, :view alias EventosWeb.AccountView diff --git a/lib/eventos_web/views/category_view.ex b/lib/eventos_web/views/category_view.ex index a6044fac2..ae42637d6 100644 --- a/lib/eventos_web/views/category_view.ex +++ b/lib/eventos_web/views/category_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.CategoryView do + @moduledoc """ + View for Categories + """ use EventosWeb, :view alias EventosWeb.CategoryView diff --git a/lib/eventos_web/views/changeset_view.ex b/lib/eventos_web/views/changeset_view.ex index b3127116b..3399463ff 100644 --- a/lib/eventos_web/views/changeset_view.ex +++ b/lib/eventos_web/views/changeset_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.ChangesetView do + @moduledoc """ + View for changesets in case of errors + """ use EventosWeb, :view @doc """ diff --git a/lib/eventos_web/views/error_view.ex b/lib/eventos_web/views/error_view.ex index aed4ef306..cc43cda19 100644 --- a/lib/eventos_web/views/error_view.ex +++ b/lib/eventos_web/views/error_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.ErrorView do + @moduledoc """ + View for errors + """ use EventosWeb, :view def render("404.html", _assigns) do diff --git a/lib/eventos_web/views/event_view.ex b/lib/eventos_web/views/event_view.ex index 863ce2f52..3e013157a 100644 --- a/lib/eventos_web/views/event_view.ex +++ b/lib/eventos_web/views/event_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.EventView do + @moduledoc """ + View for Events + """ use EventosWeb, :view alias EventosWeb.EventView diff --git a/lib/eventos_web/views/group_view.ex b/lib/eventos_web/views/group_view.ex index 765fe378c..883054078 100644 --- a/lib/eventos_web/views/group_view.ex +++ b/lib/eventos_web/views/group_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.GroupView do + @moduledoc """ + View for Groups + """ use EventosWeb, :view alias EventosWeb.GroupView diff --git a/lib/eventos_web/views/member_view.ex b/lib/eventos_web/views/member_view.ex index 8d9071fdf..f1def8a22 100644 --- a/lib/eventos_web/views/member_view.ex +++ b/lib/eventos_web/views/member_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.MemberView do + @moduledoc """ + View for Members + """ use EventosWeb, :view alias EventosWeb.MemberView diff --git a/lib/eventos_web/views/page_view.ex b/lib/eventos_web/views/page_view.ex index 99fb38eb8..53b269f16 100644 --- a/lib/eventos_web/views/page_view.ex +++ b/lib/eventos_web/views/page_view.ex @@ -1,3 +1,6 @@ defmodule EventosWeb.PageView do + @moduledoc """ + View for our webapp + """ use EventosWeb, :view end diff --git a/lib/eventos_web/views/participant_view.ex b/lib/eventos_web/views/participant_view.ex index f98b80b94..123950fb8 100644 --- a/lib/eventos_web/views/participant_view.ex +++ b/lib/eventos_web/views/participant_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.ParticipantView do + @moduledoc """ + View for Participants + """ use EventosWeb, :view alias EventosWeb.ParticipantView diff --git a/lib/eventos_web/views/request_view.ex b/lib/eventos_web/views/request_view.ex index db5506770..fc7e3b1f9 100644 --- a/lib/eventos_web/views/request_view.ex +++ b/lib/eventos_web/views/request_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.RequestView do + @moduledoc """ + View for event request + """ use EventosWeb, :view alias EventosWeb.RequestView diff --git a/lib/eventos_web/views/session_view.ex b/lib/eventos_web/views/session_view.ex index 118b44d0d..5ed81d091 100644 --- a/lib/eventos_web/views/session_view.ex +++ b/lib/eventos_web/views/session_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.SessionView do + @moduledoc """ + View for event Sessions + """ use EventosWeb, :view alias EventosWeb.SessionView diff --git a/lib/eventos_web/views/tag_view.ex b/lib/eventos_web/views/tag_view.ex index 15045fa05..3508ed97a 100644 --- a/lib/eventos_web/views/tag_view.ex +++ b/lib/eventos_web/views/tag_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.TagView do + @moduledoc """ + View for Tags + """ use EventosWeb, :view alias EventosWeb.TagView diff --git a/lib/eventos_web/views/track_view.ex b/lib/eventos_web/views/track_view.ex index d91a47fb8..15eb35579 100644 --- a/lib/eventos_web/views/track_view.ex +++ b/lib/eventos_web/views/track_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.TrackView do + @moduledoc """ + View for Tracks + """ use EventosWeb, :view alias EventosWeb.TrackView diff --git a/lib/eventos_web/views/user_session_view.ex b/lib/eventos_web/views/user_session_view.ex index 2a0e4cce0..12298808d 100644 --- a/lib/eventos_web/views/user_session_view.ex +++ b/lib/eventos_web/views/user_session_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.UserSessionView do + @moduledoc """ + View for user Sessions + """ use EventosWeb, :view def render("token.json", %{token: token, user: user}) do diff --git a/lib/eventos_web/views/user_view.ex b/lib/eventos_web/views/user_view.ex index e070018d0..f3db6669c 100644 --- a/lib/eventos_web/views/user_view.ex +++ b/lib/eventos_web/views/user_view.ex @@ -1,4 +1,7 @@ defmodule EventosWeb.UserView do + @moduledoc """ + View for Users + """ use EventosWeb, :view alias EventosWeb.UserView alias EventosWeb.AccountView diff --git a/mix.exs b/mix.exs index 874ff60d7..9dd679e08 100644 --- a/mix.exs +++ b/mix.exs @@ -12,7 +12,11 @@ defmodule Eventos.Mixfile do aliases: aliases(), deps: deps(), test_coverage: [tool: ExCoveralls], - preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test] + preferred_cli_env: ["coveralls": :test, "coveralls.detail": :test, "coveralls.post": :test, "coveralls.html": :test], + name: "Eventos", + source_url: "https://framagit.org/tcit/eventos", + homepage_url: "https://framagit.org/tcit/eventos", + docs: [main: "Eventos"] ] end @@ -58,6 +62,8 @@ defmodule Eventos.Mixfile do {:credo, "~> 0.8", only: [:dev, :test], runtime: false}, {:excoveralls, "~> 0.8", only: :test}, {:dogma, "~> 0.1", only: :dev}, + {:icalendar, "~> 0.6"}, + {:ex_doc, "~> 0.16", only: :dev, runtime: false} ] end diff --git a/mix.lock b/mix.lock index 53a8b4ba8..332a6c4ab 100644 --- a/mix.lock +++ b/mix.lock @@ -13,9 +13,11 @@ "db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, "dogma": {:hex, :dogma, "0.1.15", "5bceba9054b2b97a4adcb2ab4948ca9245e5258b883946e82d32f785340fd411", [], [{:poison, ">= 2.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, + "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [], [], "hexpm"}, "ecto": {:hex, :ecto, "2.2.7", "2074106ff4a5cd9cb2b54b12ca087c4b659ddb3f6b50be4562883c1d763fb031", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "ecto_autoslug_field": {:hex, :ecto_autoslug_field, "0.4.0", "f07db9ac545c7489b49ae77d0675a4a1635af821d3d4c95b8399edfa8f779deb", [], [{:ecto, ">= 2.1.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:slugger, ">= 0.2.0", [hex: :slugger, repo: "hexpm", optional: false]}], "hexpm"}, "elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], [], "hexpm"}, + "ex_doc": {:hex, :ex_doc, "0.18.1", "37c69d2ef62f24928c1f4fdc7c724ea04aecfdf500c4329185f8e3649c915baf", [], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"}, "ex_machina": {:hex, :ex_machina, "2.1.0", "4874dc9c78e7cf2d429f24dc3c4005674d4e4da6a08be961ffccc08fb528e28b", [], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"}, "excoveralls": {:hex, :excoveralls, "0.8.0", "99d2691d3edf8612f128be3f9869c4d44b91c67cec92186ce49470ae7a7404cf", [], [{:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"}, @@ -26,6 +28,7 @@ "guardian": {:hex, :guardian, "1.0.1", "db0fbaf571c3b874785818b7272eaf5f1ed97a2f9b1f8bc5dc8b0fb8f8f7bb06", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.0 or ~> 1.2 or ~> 1.3", [hex: :phoenix, repo: "hexpm", optional: true]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}, {:uuid, ">= 1.1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"}, "guardian_db": {:hex, :guardian_db, "1.1.0", "45ab94206cce38f7443dc27de6dc52966ccbdeff65ca1b1f11a6d8f3daceb556", [], [{:ecto, "~> 2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:guardian, "~> 1.0", [hex: :guardian, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"}, "hackney": {:hex, :hackney, "1.10.1", "c38d0ca52ea80254936a32c45bb7eb414e7a96a521b4ce76d00a69753b157f21", [], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"}, + "icalendar": {:hex, :icalendar, "0.6.0", "0e30054b234752fa1ec3e2b928101f8c98f70067766590360d7790b41faab315", [], [{:timex, "~> 3.0", [hex: :timex, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, "jose": {:hex, :jose, "1.8.4", "7946d1e5c03a76ac9ef42a6e6a20001d35987afd68c2107bcd8f01a84e75aa73", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"}, "jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [], [], "hexpm"}, diff --git a/test/eventos/accounts/accounts_test.exs b/test/eventos/accounts/accounts_test.exs index bf7c4122a..fcfc4bde0 100644 --- a/test/eventos/accounts/accounts_test.exs +++ b/test/eventos/accounts/accounts_test.exs @@ -36,7 +36,7 @@ defmodule Eventos.AccountsTest do assert account.domain == "some domain" assert account.private_key == "some private_key" assert account.public_key == "some public_key" - assert account.suspended == true + assert account.suspended assert account.uri == "some uri" assert account.url == "some url" assert account.username == "some username" @@ -55,7 +55,7 @@ defmodule Eventos.AccountsTest do assert account.domain == "some updated domain" assert account.private_key == "some updated private_key" assert account.public_key == "some updated public_key" - assert account.suspended == false + refute account.suspended assert account.uri == "some updated uri" assert account.url == "some updated url" assert account.username == "some updated username" diff --git a/test/eventos/events/events_test.exs b/test/eventos/events/events_test.exs index b22466b6f..6ca644303 100644 --- a/test/eventos/events/events_test.exs +++ b/test/eventos/events/events_test.exs @@ -9,11 +9,11 @@ defmodule Eventos.EventsTest do @account_valid_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", private_key: "some private_key", public_key: "some public_key", suspended: true, uri: "some uri", url: "some url", username: "some username"} @event_valid_attrs %{begins_on: "2010-04-17 14:00:00.000000Z", description: "some description", ends_on: "2010-04-17 14:00:00.000000Z", title: "some title"} - def account_fixture(attrs \\ %{}) do + def account_fixture do insert(:account) end - def event_fixture(attrs \\ %{}) do + def event_fixture do insert(:event, organizer: account_fixture()) end @@ -274,7 +274,7 @@ defmodule Eventos.EventsTest do event = event_fixture() account = account_fixture() valid_attrs = Map.put(@valid_attrs, :event_id, event.id) - |> Map.put(:account_id, account.id) + valid_attrs = Map.put(valid_attrs, :account_id, account.id) {:ok, participant} = attrs |> Enum.into(valid_attrs) @@ -297,7 +297,7 @@ defmodule Eventos.EventsTest do account = account_fixture() event = event_fixture() valid_attrs = Map.put(@valid_attrs, :event_id, event.id) - |> Map.put(:account_id, account.id) + valid_attrs = Map.put(valid_attrs, :account_id, account.id) assert {:ok, %Participant{} = participant} = Events.create_participant(valid_attrs) assert participant.role == 42 end diff --git a/test/eventos/groups/groups_test.exs b/test/eventos/groups/groups_test.exs index 1b8faa678..03cd64255 100644 --- a/test/eventos/groups/groups_test.exs +++ b/test/eventos/groups/groups_test.exs @@ -32,7 +32,7 @@ defmodule Eventos.GroupsTest do test "create_group/1 with valid data creates a group" do assert {:ok, %Group{} = group} = Groups.create_group(@valid_attrs) assert group.description == "some description" - assert group.suspended == true + assert group.suspended assert group.title == "some title" assert group.uri == "some uri" assert group.url == "some url" @@ -47,7 +47,7 @@ defmodule Eventos.GroupsTest do assert {:ok, group} = Groups.update_group(group, @update_attrs) assert %Group{} = group assert group.description == "some updated description" - assert group.suspended == false + refute group.suspended assert group.title == "some updated title" assert group.uri == "some updated uri" assert group.url == "some updated url" diff --git a/test/eventos_web/controllers/account_controller_test.exs b/test/eventos_web/controllers/account_controller_test.exs index 87b0c9308..f41049c4d 100644 --- a/test/eventos_web/controllers/account_controller_test.exs +++ b/test/eventos_web/controllers/account_controller_test.exs @@ -6,8 +6,6 @@ defmodule EventosWeb.AccountControllerTest do alias Eventos.Accounts @create_attrs %{description: "some description", display_name: "some display_name", domain: "some domain", private_key: "some private_key", public_key: "some public_key", suspended: true, uri: "some uri", url: "some url", username: "some username"} - @update_attrs %{description: "some updated description", display_name: "some updated display_name", domain: "some updated domain", private_key: "some updated private_key", public_key: "some updated public_key", suspended: false, uri: "some updated uri", url: "some updated url", username: "some updated username"} - @invalid_attrs %{description: nil, display_name: nil, domain: nil, private_key: nil, public_key: nil, suspended: nil, uri: nil, url: nil, username: nil} def fixture(:account) do {:ok, account} = Accounts.create_account(@create_attrs) diff --git a/test/eventos_web/controllers/user_controller_test.exs b/test/eventos_web/controllers/user_controller_test.exs index 826c0f8df..2112df862 100644 --- a/test/eventos_web/controllers/user_controller_test.exs +++ b/test/eventos_web/controllers/user_controller_test.exs @@ -7,7 +7,7 @@ defmodule EventosWeb.UserControllerTest do alias Eventos.Accounts.User @create_attrs %{email: "foo@bar.tld", password: "some password_hash", username: "some username"} - @update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"} + # @update_attrs %{email: "foo@fighters.tld", password: "some updated password_hash", username: "some updated username"} @invalid_attrs %{email: "not an email", password: nil, username: nil} def fixture(:user) do @@ -33,6 +33,7 @@ defmodule EventosWeb.UserControllerTest do test "renders user when data is valid", %{conn: conn} do conn = post conn, user_path(conn, :create), @create_attrs assert %{"user" => %{"id" => id}} = json_response(conn, 201) + assert id > 0 end test "renders errors when data is invalid", %{conn: conn} do diff --git a/test/eventos_web/controllers/user_session_controller_test.exs b/test/eventos_web/controllers/user_session_controller_test.exs index e69de29bb..8b1378917 100644 --- a/test/eventos_web/controllers/user_session_controller_test.exs +++ b/test/eventos_web/controllers/user_session_controller_test.exs @@ -0,0 +1 @@ + diff --git a/test/support/factory.ex b/test/support/factory.ex index 139bedfe1..33f963349 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,4 +1,7 @@ defmodule Eventos.Factory do + @moduledoc """ + Factory for fixtures with ExMachina + """ # with Ecto use ExMachina.Ecto, repo: Eventos.Repo @@ -12,7 +15,7 @@ defmodule Eventos.Factory do end def account_factory do - {:ok, {privkey, pubkey}} = RsaEx.generate_keypair("4096") + {:ok, {_, pubkey}} = RsaEx.generate_keypair("4096") %Eventos.Accounts.Account{ username: sequence("Thomas"), domain: nil, @@ -47,4 +50,4 @@ defmodule Eventos.Factory do event: build(:event) } end -end \ No newline at end of file +end diff --git a/test/test_helper.exs b/test/test_helper.exs index acb591956..3e158a7e6 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -3,4 +3,3 @@ ExUnit.start() Ecto.Adapters.SQL.Sandbox.mode(Eventos.Repo, :manual) -