You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
792 B
Elixir
30 lines
792 B
Elixir
defmodule Asciinema.Fixtures do
|
|
alias Asciinema.{Repo, Asciicasts}
|
|
alias Asciinema.Accounts.User
|
|
|
|
def fixture(what, attrs \\ %{})
|
|
|
|
def fixture(:upload, attrs) do
|
|
path = Map.get(attrs, :path) || "1/asciicast.json"
|
|
filename = Path.basename(path)
|
|
%Plug.Upload{path: "spec/fixtures/#{path}",
|
|
filename: filename,
|
|
content_type: "application/json"}
|
|
end
|
|
|
|
def fixture(:user, attrs) do
|
|
attrs = Map.merge(%{username: "test",
|
|
email: "test@example.com"}, attrs)
|
|
%User{}
|
|
|> User.create_changeset(attrs)
|
|
|> Repo.insert!
|
|
end
|
|
|
|
def fixture(:asciicast, _attrs) do
|
|
user = fixture(:user)
|
|
upload = fixture(:upload)
|
|
{:ok, asciicast} = Asciicasts.create_asciicast(user, upload)
|
|
asciicast
|
|
end
|
|
end
|