63 lines
1.3 KiB
Elixir
63 lines
1.3 KiB
Elixir
defmodule PhoenixRealWorld.BlogsFixtures do
|
|
@moduledoc """
|
|
This module defines test helpers for creating
|
|
entities via the `PhoenixRealWorld.Blogs` context.
|
|
"""
|
|
|
|
@doc """
|
|
Generate a article.
|
|
"""
|
|
|
|
import PhoenixRealWorld.AccountsFixtures #←追加
|
|
|
|
def article_fixture(attrs \\ %{}) do
|
|
{:ok, article} =
|
|
attrs
|
|
|> Enum.into(%{
|
|
body: "some body",
|
|
title: "some title",
|
|
author_id: user_fixture().id #←追加
|
|
})
|
|
|> PhoenixRealWorld.Blogs.create_article()
|
|
|
|
article
|
|
end
|
|
|
|
@doc """
|
|
Generate a comment.
|
|
"""
|
|
|
|
import PhoenixRealWorld.AccountsFixtures #←追加
|
|
|
|
def comment_fixture(attrs \\ %{}) do
|
|
{:ok, comment} =
|
|
attrs
|
|
|> Enum.into(%{
|
|
body: "some body",
|
|
article_id: article_fixture().id, #←追加
|
|
author_id: user_fixture().id #←追加
|
|
})
|
|
|> PhoenixRealWorld.Blogs.create_comment()
|
|
|
|
comment
|
|
end
|
|
|
|
@doc """
|
|
Generate a unique tag tag.
|
|
"""
|
|
def unique_tag_tag, do: "some tag#{System.unique_integer([:positive])}"
|
|
|
|
@doc """
|
|
Generate a tag.
|
|
"""
|
|
def tag_fixture(attrs \\ %{}) do
|
|
{:ok, tag} =
|
|
attrs
|
|
|> Enum.into(%{
|
|
tag: unique_tag_tag()
|
|
})
|
|
|> PhoenixRealWorld.Blogs.create_tag()
|
|
|
|
tag
|
|
end
|
|
end
|