Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule PhoenixApi.QuoteControllerTest do
- use PhoenixApi.ConnCase
- alias PhoenixApi.Quote
- alias PhoenixApi.User
- alias PhoenixApi.Session
- @valid_attrs %{author: "some content", quote: "some content"}
- @invalid_attrs %{}
- setup %{conn: conn} do
- user = create_user("cristiano")
- session = create_session(user)
- conn = conn
- |> put_req_header("accept", "application/json")
- |> put_req_header("authorization", "Token token=\"#{session.token}\"")
- {:ok, conn: conn, current_user: user}
- end
- def create_user(%{name: name}) do
- Repo.insert! %User{ email: "#{name}.codelab@gmail.com", name: String.capitalize(name), password: "qwe@rty#$&"}
- end
- def create_session(user) do
- Session.create_changeset(%Session{user_id: user.id}, %{}) |> Repo.insert!
- end
- def create_quote(%{author: _author, user_id: _user_id} = options) do
- Quote.changeset(%Quote{}, options) |> Repo.insert!
- end
- test "lists all entries on index", %{conn: conn, current_user: current_user} do
- create_quote(%{author: "Stephen Chbosky", quote: "We accept the love we think we deserve.", user_id: current_user.id})
- other_user = create_user("otte")
- create_quote(%{author: "Francoise Sagan", quote: "Art must take reality by surprise.", user_id: other_user.id})
- conn = get conn, quote_path(conn, :index)
- assert Enum.count(json_response(conn, 200)["data"]) == 1
- assert %{"author" => "Stephen Chbosky"} = hd(json_response(conn, 200)["data"])
- end
- test "create
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement