Delete a record

Ecto for Beginners : part 14 of 22 published on Sep 07, 2015

/test/models/posts/delete_test.exs

defmodule Readdit.Posts.DeleteTest do use ExUnit.Case use Readdit.ConnCase

test “delete! post” do

post = %Readdit.Post{title: "Han Shot shot first"} |> Readdit.Repo.insert!

post = Readdit.Repo.delete!(post)

post = Readdit.Post |> Readdit.Repo.get(post.id)

assert post == nil

end

test “delete post” do

post = %Readdit.Post{title: "Han Shot shot first"} |> Readdit.Repo.insert!

{ :ok, post } = Readdit.Repo.delete(post)

post = Readdit.Post |> Readdit.Repo.get(post.id)

assert post == nil

end

test “post |> delete!” do

post = %Readdit.Post{title: "Han Shot shot first"} |> Readdit.Repo.insert!

post = post |> Readdit.Repo.delete!

post = Readdit.Post |> Readdit.Repo.get(post.id)

assert post == nil

end

end

Next: Has Many Relationship