Skip to content
2 changes: 1 addition & 1 deletion lib/cadet/accounts/authorization.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defmodule Cadet.Accounts.Authorization do
@required_fields ~w(provider uid token)a
@optional_fields ~w(refresh_token expires_at)a

def changeset(authorization, params \\ :empty) do
def changeset(authorization, params \\ %{}) do
authorization
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/accounts/form/registration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Cadet.Accounts.Form.Registration do

@email_format ~r/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/

def changeset(registration, params \\ :empty) do
def changeset(registration, params \\ %{}) do
registration
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Cadet.Accounts.User do
@required_fields ~w(first_name role)a
@optional_fields ~w(last_name)a

def changeset(user, params \\ :empty) do
def changeset(user, params \\ %{}) do
user
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
Expand Down
13 changes: 3 additions & 10 deletions lib/cadet/course.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,10 @@ defmodule Cadet.Course do
end

def delete_material(material = %Material{}) do
cond do
material == nil ->
{:error, :not_found}

material.file != nil ->
Upload.delete({material.file, material})
Repo.delete(material)

true ->
Repo.delete(material)
if material.file do
Upload.delete({material.file, material})
end
Repo.delete(material)
end

@doc """
Expand Down
2 changes: 1 addition & 1 deletion lib/cadet/course/material.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ defmodule Cadet.Course.Material do

def changeset(material, attrs \\ %{}) do
material
|> cast(attrs, @required_fields ++ @optional_fields)
|> cast_attachments(attrs, @optional_file_fields)
|> cast(attrs, @required_fields ++ @optional_fields)
|> validate_changeset
end

Expand Down
1 change: 1 addition & 0 deletions lib/cadet/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Cadet.Factory do
Factory for testing
"""
use ExMachina.Ecto, repo: Cadet.Repo
@dialyzer {:no_return, fields_for: 1} # fields_for has been deprecated, only raising exception

alias Cadet.Accounts.User
alias Cadet.Accounts.Authorization
Expand Down
1 change: 0 additions & 1 deletion lib/cadet_web/controllers/session_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ defmodule CadetWeb.SessionController do
case reason do
:not_found -> "E-mail not registered in the system"
:invalid_password -> "Invalid e-mail or password"
_ -> "Unknown"
end
end
end
6 changes: 5 additions & 1 deletion lib/mix/tasks/digest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ defmodule Mix.Tasks.Cadet.Digest do
use Mix.Task

def run(args) do
Dotenv.load!()
try do
Dotenv.load!()
rescue
e in RuntimeError -> e
end
Mix.Shell.IO.cmd("cd frontend && npm run build")
:ok = Mix.Tasks.Phx.Digest.run(args)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/mix/tasks/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ defmodule Mix.Tasks.Cadet.Server do
use Mix.Task

def run(args) do
Dotenv.load!()
try do
Dotenv.load!()
rescue
e in RuntimeError -> e
end
:ok = Mix.Tasks.Phx.Server.run(args)
end
end
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Cadet.Mixfile do
"coveralls.html": :test
],
aliases: aliases(),
deps: deps()
deps: deps(),
dialyzer: [plt_add_apps: [:mix, :ex_unit]]
]
end

Expand Down Expand Up @@ -56,6 +57,7 @@ defmodule Cadet.Mixfile do
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:credo, "~> 0.8", only: [:dev, :test], runtime: false},
{:excoveralls, "~> 0.8", only: :test},
{:dialyxir, "~> 0.5", only: [:dev, :test], runtime: false},
{:arc, "~> 0.8.0"},
{:arc_ecto, "~> 0.7.0"},
{:timex, "~> 3.0"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"credo": {:hex, :credo, "0.9.1", "f021affa11b32a94dc2e807a6472ce0914289c9132f99644a97fc84432b202a1", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [], [{: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", [], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"dotenv": {:hex, :dotenv, "2.0.0", "87e77a94e54c20eca49989876395e26878b109f016f9fd9c42b65bb9c59bca3f", [], [], "hexpm"},
"ecto": {:hex, :ecto, "2.2.6", "3fd1067661d6d64851a0d4db9acd9e884c00d2d1aa41cc09da687226cf894661", [], [{: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_enum": {:hex, :ecto_enum, "1.1.0", "d44fe2ce6e1c0e907e7c3b6456a69e0f1d662348d8b4e2a662ba312223d8ff62", [], [{:ecto, ">= 2.0.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, ">= 0.0.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm"},
Expand Down
9 changes: 3 additions & 6 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ defmodule CadetWeb.ConnCase do
conn = Phoenix.ConnTest.build_conn()

if tags[:authenticate] != nil do
{:ok, conn: authenticate(conn, tags[:authenticate])}
user = Cadet.Factory.insert(:user, %{role: tags[:authenticate]})
conn = Cadet.Auth.Guardian.Plug.sign_in(conn, user)
{:ok, conn: conn}
else
{:ok, conn: conn}
end
end

defp authenticate(conn, role) do
user = Cadet.Factory.insert(:user, %{role: role})
Cadet.Auth.Guardian.Plug.sign_in(conn, user)
end
end