Initial commit
This commit is contained in:
66
test/confient/account_test.exs
Normal file
66
test/confient/account_test.exs
Normal file
@@ -0,0 +1,66 @@
|
||||
defmodule Confient.AccountTest do
|
||||
use Confient.DataCase
|
||||
|
||||
alias Confient.Account
|
||||
|
||||
describe "users" do
|
||||
alias Confient.Account.User
|
||||
|
||||
@valid_attrs %{encrypted_password: "some encrypted_password", username: "some username"}
|
||||
@update_attrs %{encrypted_password: "some updated encrypted_password", username: "some updated username"}
|
||||
@invalid_attrs %{encrypted_password: nil, username: nil}
|
||||
|
||||
def user_fixture(attrs \\ %{}) do
|
||||
{:ok, user} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Account.create_user()
|
||||
|
||||
user
|
||||
end
|
||||
|
||||
test "list_users/0 returns all users" do
|
||||
user = user_fixture()
|
||||
assert Account.list_users() == [user]
|
||||
end
|
||||
|
||||
test "get_user!/1 returns the user with given id" do
|
||||
user = user_fixture()
|
||||
assert Account.get_user!(user.id) == user
|
||||
end
|
||||
|
||||
test "create_user/1 with valid data creates a user" do
|
||||
assert {:ok, %User{} = user} = Account.create_user(@valid_attrs)
|
||||
assert user.encrypted_password == "some encrypted_password"
|
||||
assert user.username == "some username"
|
||||
end
|
||||
|
||||
test "create_user/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Account.create_user(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_user/2 with valid data updates the user" do
|
||||
user = user_fixture()
|
||||
assert {:ok, %User{} = user} = Account.update_user(user, @update_attrs)
|
||||
assert user.encrypted_password == "some updated encrypted_password"
|
||||
assert user.username == "some updated username"
|
||||
end
|
||||
|
||||
test "update_user/2 with invalid data returns error changeset" do
|
||||
user = user_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Account.update_user(user, @invalid_attrs)
|
||||
assert user == Account.get_user!(user.id)
|
||||
end
|
||||
|
||||
test "delete_user/1 deletes the user" do
|
||||
user = user_fixture()
|
||||
assert {:ok, %User{}} = Account.delete_user(user)
|
||||
assert_raise Ecto.NoResultsError, fn -> Account.get_user!(user.id) end
|
||||
end
|
||||
|
||||
test "change_user/1 returns a user changeset" do
|
||||
user = user_fixture()
|
||||
assert %Ecto.Changeset{} = Account.change_user(user)
|
||||
end
|
||||
end
|
||||
end
|
||||
125
test/confient/school_test.exs
Normal file
125
test/confient/school_test.exs
Normal file
@@ -0,0 +1,125 @@
|
||||
defmodule Confient.SchoolTest do
|
||||
use Confient.DataCase
|
||||
|
||||
alias Confient.School
|
||||
|
||||
describe "classes" do
|
||||
alias Confient.School.Class
|
||||
|
||||
@valid_attrs %{name: "some name"}
|
||||
@update_attrs %{name: "some updated name"}
|
||||
@invalid_attrs %{name: nil}
|
||||
|
||||
def class_fixture(attrs \\ %{}) do
|
||||
{:ok, class} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> School.create_class()
|
||||
|
||||
class
|
||||
end
|
||||
|
||||
test "list_classes/0 returns all classes" do
|
||||
class = class_fixture()
|
||||
assert School.list_classes() == [class]
|
||||
end
|
||||
|
||||
test "get_class!/1 returns the class with given id" do
|
||||
class = class_fixture()
|
||||
assert School.get_class!(class.id) == class
|
||||
end
|
||||
|
||||
test "create_class/1 with valid data creates a class" do
|
||||
assert {:ok, %Class{} = class} = School.create_class(@valid_attrs)
|
||||
assert class.name == "some name"
|
||||
end
|
||||
|
||||
test "create_class/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = School.create_class(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_class/2 with valid data updates the class" do
|
||||
class = class_fixture()
|
||||
assert {:ok, %Class{} = class} = School.update_class(class, @update_attrs)
|
||||
assert class.name == "some updated name"
|
||||
end
|
||||
|
||||
test "update_class/2 with invalid data returns error changeset" do
|
||||
class = class_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = School.update_class(class, @invalid_attrs)
|
||||
assert class == School.get_class!(class.id)
|
||||
end
|
||||
|
||||
test "delete_class/1 deletes the class" do
|
||||
class = class_fixture()
|
||||
assert {:ok, %Class{}} = School.delete_class(class)
|
||||
assert_raise Ecto.NoResultsError, fn -> School.get_class!(class.id) end
|
||||
end
|
||||
|
||||
test "change_class/1 returns a class changeset" do
|
||||
class = class_fixture()
|
||||
assert %Ecto.Changeset{} = School.change_class(class)
|
||||
end
|
||||
end
|
||||
|
||||
describe "students" do
|
||||
alias Confient.School.Student
|
||||
|
||||
@valid_attrs %{firstname: "some firstname", lastname: "some lastname"}
|
||||
@update_attrs %{firstname: "some updated firstname", lastname: "some updated lastname"}
|
||||
@invalid_attrs %{firstname: nil, lastname: nil}
|
||||
|
||||
def student_fixture(attrs \\ %{}) do
|
||||
{:ok, student} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> School.create_student()
|
||||
|
||||
student
|
||||
end
|
||||
|
||||
test "list_students/0 returns all students" do
|
||||
student = student_fixture()
|
||||
assert School.list_students() == [student]
|
||||
end
|
||||
|
||||
test "get_student!/1 returns the student with given id" do
|
||||
student = student_fixture()
|
||||
assert School.get_student!(student.id) == student
|
||||
end
|
||||
|
||||
test "create_student/1 with valid data creates a student" do
|
||||
assert {:ok, %Student{} = student} = School.create_student(@valid_attrs)
|
||||
assert student.firstname == "some firstname"
|
||||
assert student.lastname == "some lastname"
|
||||
end
|
||||
|
||||
test "create_student/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = School.create_student(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_student/2 with valid data updates the student" do
|
||||
student = student_fixture()
|
||||
assert {:ok, %Student{} = student} = School.update_student(student, @update_attrs)
|
||||
assert student.firstname == "some updated firstname"
|
||||
assert student.lastname == "some updated lastname"
|
||||
end
|
||||
|
||||
test "update_student/2 with invalid data returns error changeset" do
|
||||
student = student_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = School.update_student(student, @invalid_attrs)
|
||||
assert student == School.get_student!(student.id)
|
||||
end
|
||||
|
||||
test "delete_student/1 deletes the student" do
|
||||
student = student_fixture()
|
||||
assert {:ok, %Student{}} = School.delete_student(student)
|
||||
assert_raise Ecto.NoResultsError, fn -> School.get_student!(student.id) end
|
||||
end
|
||||
|
||||
test "change_student/1 returns a student changeset" do
|
||||
student = student_fixture()
|
||||
assert %Ecto.Changeset{} = School.change_student(student)
|
||||
end
|
||||
end
|
||||
end
|
||||
127
test/confient/works_test.exs
Normal file
127
test/confient/works_test.exs
Normal file
@@ -0,0 +1,127 @@
|
||||
defmodule Confient.WorksTest do
|
||||
use Confient.DataCase
|
||||
|
||||
alias Confient.Works
|
||||
|
||||
describe "assignements" do
|
||||
alias Confient.Works.Assignement
|
||||
|
||||
@valid_attrs %{due: ~D[2010-04-17], title: "some title"}
|
||||
@update_attrs %{due: ~D[2011-05-18], title: "some updated title"}
|
||||
@invalid_attrs %{due: nil, title: nil}
|
||||
|
||||
def assignement_fixture(attrs \\ %{}) do
|
||||
{:ok, assignement} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Works.create_assignement()
|
||||
|
||||
assignement
|
||||
end
|
||||
|
||||
test "list_assignements/0 returns all assignements" do
|
||||
assignement = assignement_fixture()
|
||||
assert Works.list_assignements() == [assignement]
|
||||
end
|
||||
|
||||
test "get_assignement!/1 returns the assignement with given id" do
|
||||
assignement = assignement_fixture()
|
||||
assert Works.get_assignement!(assignement.id) == assignement
|
||||
end
|
||||
|
||||
test "create_assignement/1 with valid data creates a assignement" do
|
||||
assert {:ok, %Assignement{} = assignement} = Works.create_assignement(@valid_attrs)
|
||||
assert assignement.due == ~D[2010-04-17]
|
||||
assert assignement.title == "some title"
|
||||
end
|
||||
|
||||
test "create_assignement/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Works.create_assignement(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_assignement/2 with valid data updates the assignement" do
|
||||
assignement = assignement_fixture()
|
||||
assert {:ok, %Assignement{} = assignement} = Works.update_assignement(assignement, @update_attrs)
|
||||
assert assignement.due == ~D[2011-05-18]
|
||||
assert assignement.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_assignement/2 with invalid data returns error changeset" do
|
||||
assignement = assignement_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Works.update_assignement(assignement, @invalid_attrs)
|
||||
assert assignement == Works.get_assignement!(assignement.id)
|
||||
end
|
||||
|
||||
test "delete_assignement/1 deletes the assignement" do
|
||||
assignement = assignement_fixture()
|
||||
assert {:ok, %Assignement{}} = Works.delete_assignement(assignement)
|
||||
assert_raise Ecto.NoResultsError, fn -> Works.get_assignement!(assignement.id) end
|
||||
end
|
||||
|
||||
test "change_assignement/1 returns a assignement changeset" do
|
||||
assignement = assignement_fixture()
|
||||
assert %Ecto.Changeset{} = Works.change_assignement(assignement)
|
||||
end
|
||||
end
|
||||
|
||||
describe "assignments" do
|
||||
alias Confient.Works.Assignment
|
||||
|
||||
@valid_attrs %{due: ~D[2010-04-17], title: "some title"}
|
||||
@update_attrs %{due: ~D[2011-05-18], title: "some updated title"}
|
||||
@invalid_attrs %{due: nil, title: nil}
|
||||
|
||||
def assignment_fixture(attrs \\ %{}) do
|
||||
{:ok, assignment} =
|
||||
attrs
|
||||
|> Enum.into(@valid_attrs)
|
||||
|> Works.create_assignment()
|
||||
|
||||
assignment
|
||||
end
|
||||
|
||||
test "list_assignments/0 returns all assignments" do
|
||||
assignment = assignment_fixture()
|
||||
assert Works.list_assignments() == [assignment]
|
||||
end
|
||||
|
||||
test "get_assignment!/1 returns the assignment with given id" do
|
||||
assignment = assignment_fixture()
|
||||
assert Works.get_assignment!(assignment.id) == assignment
|
||||
end
|
||||
|
||||
test "create_assignment/1 with valid data creates a assignment" do
|
||||
assert {:ok, %Assignment{} = assignment} = Works.create_assignment(@valid_attrs)
|
||||
assert assignment.due == ~D[2010-04-17]
|
||||
assert assignment.title == "some title"
|
||||
end
|
||||
|
||||
test "create_assignment/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Works.create_assignment(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_assignment/2 with valid data updates the assignment" do
|
||||
assignment = assignment_fixture()
|
||||
assert {:ok, %Assignment{} = assignment} = Works.update_assignment(assignment, @update_attrs)
|
||||
assert assignment.due == ~D[2011-05-18]
|
||||
assert assignment.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_assignment/2 with invalid data returns error changeset" do
|
||||
assignment = assignment_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Works.update_assignment(assignment, @invalid_attrs)
|
||||
assert assignment == Works.get_assignment!(assignment.id)
|
||||
end
|
||||
|
||||
test "delete_assignment/1 deletes the assignment" do
|
||||
assignment = assignment_fixture()
|
||||
assert {:ok, %Assignment{}} = Works.delete_assignment(assignment)
|
||||
assert_raise Ecto.NoResultsError, fn -> Works.get_assignment!(assignment.id) end
|
||||
end
|
||||
|
||||
test "change_assignment/1 returns a assignment changeset" do
|
||||
assignment = assignment_fixture()
|
||||
assert %Ecto.Changeset{} = Works.change_assignment(assignment)
|
||||
end
|
||||
end
|
||||
end
|
||||
88
test/confient_web/controllers/assignment_controller_test.exs
Normal file
88
test/confient_web/controllers/assignment_controller_test.exs
Normal file
@@ -0,0 +1,88 @@
|
||||
defmodule ConfientWeb.AssignmentControllerTest do
|
||||
use ConfientWeb.ConnCase
|
||||
|
||||
alias Confient.Works
|
||||
|
||||
@create_attrs %{due: ~D[2010-04-17], title: "some title"}
|
||||
@update_attrs %{due: ~D[2011-05-18], title: "some updated title"}
|
||||
@invalid_attrs %{due: nil, title: nil}
|
||||
|
||||
def fixture(:assignment) do
|
||||
{:ok, assignment} = Works.create_assignment(@create_attrs)
|
||||
assignment
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all assignments", %{conn: conn} do
|
||||
conn = get(conn, Routes.assignment_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing Assignments"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new assignment" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.assignment_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New Assignment"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create assignment" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.assignment_path(conn, :create), assignment: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.assignment_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.assignment_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show Assignment"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.assignment_path(conn, :create), assignment: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New Assignment"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit assignment" do
|
||||
setup [:create_assignment]
|
||||
|
||||
test "renders form for editing chosen assignment", %{conn: conn, assignment: assignment} do
|
||||
conn = get(conn, Routes.assignment_path(conn, :edit, assignment))
|
||||
assert html_response(conn, 200) =~ "Edit Assignment"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update assignment" do
|
||||
setup [:create_assignment]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, assignment: assignment} do
|
||||
conn = put(conn, Routes.assignment_path(conn, :update, assignment), assignment: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.assignment_path(conn, :show, assignment)
|
||||
|
||||
conn = get(conn, Routes.assignment_path(conn, :show, assignment))
|
||||
assert html_response(conn, 200) =~ "some updated title"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, assignment: assignment} do
|
||||
conn = put(conn, Routes.assignment_path(conn, :update, assignment), assignment: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Assignment"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete assignment" do
|
||||
setup [:create_assignment]
|
||||
|
||||
test "deletes chosen assignment", %{conn: conn, assignment: assignment} do
|
||||
conn = delete(conn, Routes.assignment_path(conn, :delete, assignment))
|
||||
assert redirected_to(conn) == Routes.assignment_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.assignment_path(conn, :show, assignment))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_assignment(_) do
|
||||
assignment = fixture(:assignment)
|
||||
%{assignment: assignment}
|
||||
end
|
||||
end
|
||||
88
test/confient_web/controllers/class_controller_test.exs
Normal file
88
test/confient_web/controllers/class_controller_test.exs
Normal file
@@ -0,0 +1,88 @@
|
||||
defmodule ConfientWeb.ClassControllerTest do
|
||||
use ConfientWeb.ConnCase
|
||||
|
||||
alias Confient.School
|
||||
|
||||
@create_attrs %{name: "some name"}
|
||||
@update_attrs %{name: "some updated name"}
|
||||
@invalid_attrs %{name: nil}
|
||||
|
||||
def fixture(:class) do
|
||||
{:ok, class} = School.create_class(@create_attrs)
|
||||
class
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all classes", %{conn: conn} do
|
||||
conn = get(conn, Routes.class_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing Classes"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new class" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.class_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New Class"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create class" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.class_path(conn, :create), class: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.class_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.class_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show Class"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.class_path(conn, :create), class: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New Class"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit class" do
|
||||
setup [:create_class]
|
||||
|
||||
test "renders form for editing chosen class", %{conn: conn, class: class} do
|
||||
conn = get(conn, Routes.class_path(conn, :edit, class))
|
||||
assert html_response(conn, 200) =~ "Edit Class"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update class" do
|
||||
setup [:create_class]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, class: class} do
|
||||
conn = put(conn, Routes.class_path(conn, :update, class), class: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.class_path(conn, :show, class)
|
||||
|
||||
conn = get(conn, Routes.class_path(conn, :show, class))
|
||||
assert html_response(conn, 200) =~ "some updated name"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, class: class} do
|
||||
conn = put(conn, Routes.class_path(conn, :update, class), class: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Class"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete class" do
|
||||
setup [:create_class]
|
||||
|
||||
test "deletes chosen class", %{conn: conn, class: class} do
|
||||
conn = delete(conn, Routes.class_path(conn, :delete, class))
|
||||
assert redirected_to(conn) == Routes.class_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.class_path(conn, :show, class))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_class(_) do
|
||||
class = fixture(:class)
|
||||
%{class: class}
|
||||
end
|
||||
end
|
||||
8
test/confient_web/controllers/page_controller_test.exs
Normal file
8
test/confient_web/controllers/page_controller_test.exs
Normal file
@@ -0,0 +1,8 @@
|
||||
defmodule ConfientWeb.PageControllerTest do
|
||||
use ConfientWeb.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, "/")
|
||||
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
|
||||
end
|
||||
end
|
||||
88
test/confient_web/controllers/student_controller_test.exs
Normal file
88
test/confient_web/controllers/student_controller_test.exs
Normal file
@@ -0,0 +1,88 @@
|
||||
defmodule ConfientWeb.StudentControllerTest do
|
||||
use ConfientWeb.ConnCase
|
||||
|
||||
alias Confient.School
|
||||
|
||||
@create_attrs %{firstname: "some firstname", lastname: "some lastname"}
|
||||
@update_attrs %{firstname: "some updated firstname", lastname: "some updated lastname"}
|
||||
@invalid_attrs %{firstname: nil, lastname: nil}
|
||||
|
||||
def fixture(:student) do
|
||||
{:ok, student} = School.create_student(@create_attrs)
|
||||
student
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all students", %{conn: conn} do
|
||||
conn = get(conn, Routes.student_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing Students"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new student" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.student_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New Student"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create student" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.student_path(conn, :create), student: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.student_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.student_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show Student"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.student_path(conn, :create), student: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New Student"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit student" do
|
||||
setup [:create_student]
|
||||
|
||||
test "renders form for editing chosen student", %{conn: conn, student: student} do
|
||||
conn = get(conn, Routes.student_path(conn, :edit, student))
|
||||
assert html_response(conn, 200) =~ "Edit Student"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update student" do
|
||||
setup [:create_student]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, student: student} do
|
||||
conn = put(conn, Routes.student_path(conn, :update, student), student: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.student_path(conn, :show, student)
|
||||
|
||||
conn = get(conn, Routes.student_path(conn, :show, student))
|
||||
assert html_response(conn, 200) =~ "some updated firstname"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, student: student} do
|
||||
conn = put(conn, Routes.student_path(conn, :update, student), student: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Student"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete student" do
|
||||
setup [:create_student]
|
||||
|
||||
test "deletes chosen student", %{conn: conn, student: student} do
|
||||
conn = delete(conn, Routes.student_path(conn, :delete, student))
|
||||
assert redirected_to(conn) == Routes.student_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.student_path(conn, :show, student))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_student(_) do
|
||||
student = fixture(:student)
|
||||
%{student: student}
|
||||
end
|
||||
end
|
||||
88
test/confient_web/controllers/user_controller_test.exs
Normal file
88
test/confient_web/controllers/user_controller_test.exs
Normal file
@@ -0,0 +1,88 @@
|
||||
defmodule ConfientWeb.UserControllerTest do
|
||||
use ConfientWeb.ConnCase
|
||||
|
||||
alias Confient.Account
|
||||
|
||||
@create_attrs %{encrypted_password: "some encrypted_password", username: "some username"}
|
||||
@update_attrs %{encrypted_password: "some updated encrypted_password", username: "some updated username"}
|
||||
@invalid_attrs %{encrypted_password: nil, username: nil}
|
||||
|
||||
def fixture(:user) do
|
||||
{:ok, user} = Account.create_user(@create_attrs)
|
||||
user
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
test "lists all users", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_path(conn, :index))
|
||||
assert html_response(conn, 200) =~ "Listing Users"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new user" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_path(conn, :new))
|
||||
assert html_response(conn, 200) =~ "New User"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create user" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, Routes.user_path(conn, :create), user: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == Routes.user_path(conn, :show, id)
|
||||
|
||||
conn = get(conn, Routes.user_path(conn, :show, id))
|
||||
assert html_response(conn, 200) =~ "Show User"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, Routes.user_path(conn, :create), user: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New User"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "renders form for editing chosen user", %{conn: conn, user: user} do
|
||||
conn = get(conn, Routes.user_path(conn, :edit, user))
|
||||
assert html_response(conn, 200) =~ "Edit User"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, user: user} do
|
||||
conn = put(conn, Routes.user_path(conn, :update, user), user: @update_attrs)
|
||||
assert redirected_to(conn) == Routes.user_path(conn, :show, user)
|
||||
|
||||
conn = get(conn, Routes.user_path(conn, :show, user))
|
||||
assert html_response(conn, 200) =~ "some updated encrypted_password"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, user: user} do
|
||||
conn = put(conn, Routes.user_path(conn, :update, user), user: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit User"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete user" do
|
||||
setup [:create_user]
|
||||
|
||||
test "deletes chosen user", %{conn: conn, user: user} do
|
||||
conn = delete(conn, Routes.user_path(conn, :delete, user))
|
||||
assert redirected_to(conn) == Routes.user_path(conn, :index)
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, Routes.user_path(conn, :show, user))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_user(_) do
|
||||
user = fixture(:user)
|
||||
%{user: user}
|
||||
end
|
||||
end
|
||||
14
test/confient_web/views/error_view_test.exs
Normal file
14
test/confient_web/views/error_view_test.exs
Normal file
@@ -0,0 +1,14 @@
|
||||
defmodule ConfientWeb.ErrorViewTest do
|
||||
use ConfientWeb.ConnCase, async: true
|
||||
|
||||
# Bring render/3 and render_to_string/3 for testing custom views
|
||||
import Phoenix.View
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(ConfientWeb.ErrorView, "404.html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(ConfientWeb.ErrorView, "500.html", []) == "Internal Server Error"
|
||||
end
|
||||
end
|
||||
8
test/confient_web/views/layout_view_test.exs
Normal file
8
test/confient_web/views/layout_view_test.exs
Normal file
@@ -0,0 +1,8 @@
|
||||
defmodule ConfientWeb.LayoutViewTest do
|
||||
use ConfientWeb.ConnCase, async: true
|
||||
|
||||
# When testing helpers, you may want to import Phoenix.HTML and
|
||||
# use functions such as safe_to_string() to convert the helper
|
||||
# result into an HTML string.
|
||||
# import Phoenix.HTML
|
||||
end
|
||||
3
test/confient_web/views/page_view_test.exs
Normal file
3
test/confient_web/views/page_view_test.exs
Normal file
@@ -0,0 +1,3 @@
|
||||
defmodule ConfientWeb.PageViewTest do
|
||||
use ConfientWeb.ConnCase, async: true
|
||||
end
|
||||
40
test/support/channel_case.ex
Normal file
40
test/support/channel_case.ex
Normal file
@@ -0,0 +1,40 @@
|
||||
defmodule ConfientWeb.ChannelCase do
|
||||
@moduledoc """
|
||||
This module defines the test case to be used by
|
||||
channel tests.
|
||||
|
||||
Such tests rely on `Phoenix.ChannelTest` and also
|
||||
import other functionality to make it easier
|
||||
to build common data structures and query the data layer.
|
||||
|
||||
Finally, if the test case interacts with the database,
|
||||
we enable the SQL sandbox, so changes done to the database
|
||||
are reverted at the end of every test. If you are using
|
||||
PostgreSQL, you can even run database tests asynchronously
|
||||
by setting `use ConfientWeb.ChannelCase, async: true`, although
|
||||
this option is not recommended for other databases.
|
||||
"""
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
using do
|
||||
quote do
|
||||
# Import conveniences for testing with channels
|
||||
import Phoenix.ChannelTest
|
||||
import ConfientWeb.ChannelCase
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint ConfientWeb.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Confient.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Confient.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
end
|
||||
43
test/support/conn_case.ex
Normal file
43
test/support/conn_case.ex
Normal file
@@ -0,0 +1,43 @@
|
||||
defmodule ConfientWeb.ConnCase do
|
||||
@moduledoc """
|
||||
This module defines the test case to be used by
|
||||
tests that require setting up a connection.
|
||||
|
||||
Such tests rely on `Phoenix.ConnTest` and also
|
||||
import other functionality to make it easier
|
||||
to build common data structures and query the data layer.
|
||||
|
||||
Finally, if the test case interacts with the database,
|
||||
we enable the SQL sandbox, so changes done to the database
|
||||
are reverted at the end of every test. If you are using
|
||||
PostgreSQL, you can even run database tests asynchronously
|
||||
by setting `use ConfientWeb.ConnCase, async: true`, although
|
||||
this option is not recommended for other databases.
|
||||
"""
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
using do
|
||||
quote do
|
||||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
import Phoenix.ConnTest
|
||||
import ConfientWeb.ConnCase
|
||||
|
||||
alias ConfientWeb.Router.Helpers, as: Routes
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint ConfientWeb.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Confient.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Confient.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
{:ok, conn: Phoenix.ConnTest.build_conn()}
|
||||
end
|
||||
end
|
||||
55
test/support/data_case.ex
Normal file
55
test/support/data_case.ex
Normal file
@@ -0,0 +1,55 @@
|
||||
defmodule Confient.DataCase do
|
||||
@moduledoc """
|
||||
This module defines the setup for tests requiring
|
||||
access to the application's data layer.
|
||||
|
||||
You may define functions here to be used as helpers in
|
||||
your tests.
|
||||
|
||||
Finally, if the test case interacts with the database,
|
||||
we enable the SQL sandbox, so changes done to the database
|
||||
are reverted at the end of every test. If you are using
|
||||
PostgreSQL, you can even run database tests asynchronously
|
||||
by setting `use Confient.DataCase, async: true`, although
|
||||
this option is not recommended for other databases.
|
||||
"""
|
||||
|
||||
use ExUnit.CaseTemplate
|
||||
|
||||
using do
|
||||
quote do
|
||||
alias Confient.Repo
|
||||
|
||||
import Ecto
|
||||
import Ecto.Changeset
|
||||
import Ecto.Query
|
||||
import Confient.DataCase
|
||||
end
|
||||
end
|
||||
|
||||
setup tags do
|
||||
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Confient.Repo)
|
||||
|
||||
unless tags[:async] do
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Confient.Repo, {:shared, self()})
|
||||
end
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
@doc """
|
||||
A helper that transforms changeset errors into a map of messages.
|
||||
|
||||
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
|
||||
assert "password is too short" in errors_on(changeset).password
|
||||
assert %{password: ["password is too short"]} = errors_on(changeset)
|
||||
|
||||
"""
|
||||
def errors_on(changeset) do
|
||||
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
|
||||
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
|
||||
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
|
||||
end)
|
||||
end)
|
||||
end
|
||||
end
|
||||
2
test/test_helper.exs
Normal file
2
test/test_helper.exs
Normal file
@@ -0,0 +1,2 @@
|
||||
ExUnit.start()
|
||||
Ecto.Adapters.SQL.Sandbox.mode(Confient.Repo, :manual)
|
||||
Reference in New Issue
Block a user