From 0c11e6ff588903864182e1a58189b71ec6d69121 Mon Sep 17 00:00:00 2001 From: Robert Francis Date: Fri, 1 Mar 2019 20:23:09 +0000 Subject: [PATCH] adds tests #45 --- test/insert_test.exs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/insert_test.exs b/test/insert_test.exs index 4d5eebe..75e7a13 100644 --- a/test/insert_test.exs +++ b/test/insert_test.exs @@ -6,10 +6,24 @@ defmodule AlogTest.InsertTest do describe "Repo.insert/2 - with Comment struct:" do test "succeeds" do Repo.insert(%Comment{comment: "hi"}) - |> IO.inspect(label: "===> Result of insert") + num_comments = Comment |> Repo.all() |> length() + assert num_comments == 1 + end + + test "inserting the same comment twice fails with changeset" do + Repo.insert(%Comment{comment: "hi"}) + + {atom, _changeset} = + %Comment{} + |> Comment.changeset(%{comment: "hi"}) + |> Repo.insert() - Repo.all(Comment) - |> IO.inspect(label: "===> All comments (should only be the one)") + assert atom == :error + end + + test "inserting the same comment twice fails without changeset" do + Repo.insert(%Comment{comment: "hi"}) + Repo.insert(%Comment{comment: "hi"}) end # test "validates required fields" do