Update a record

Ecto for Beginners : part 13 of 22 published on Sep 06, 2015

/test/models/posts/update_test.exs

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

test “update! post” do

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

post = %{ post | title: "Han Shot First" }
post = Readdit.Repo.update!(post)

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

assert post.title == "Han Shot First"

end

test “update post” do

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

post = %{ post | title: "Han Shot First" }
{ :ok, post } = Readdit.Repo.update(post)

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

assert post.title == "Han Shot First"

end

test “post |> update!” do

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

post = %{ post | title: "Han Shot First" } |> Readdit.Repo.update!

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

assert post.title == "Han Shot First"

end end

Next: Delete a record