-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Test.Support.Factories.Post do | ||
@moduledoc """ | ||
Factory for `Post` | ||
""" | ||
alias EpochtalkServer.Models.Post | ||
|
||
defmacro __using__(_opts) do | ||
quote do | ||
def post_attributes_factory(%{user: user, thread: thread} = attrs) do | ||
%{ | ||
"user_id" => user.id, | ||
"thread_id" => thread.id, | ||
"content" => %{ | ||
title: Map.get(attrs, :title) || sequence(:post_title, &"RE: Post title #{&1}"), | ||
body: sequence(:post_body, &"Post body #{&1}") | ||
} | ||
} | ||
end | ||
|
||
def post_factory(%{user: user, thread: thread} = attrs) do | ||
attributes = build(:post_attributes, attrs) | ||
|
||
Post.create(attributes) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters