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.
asciinema.org/test/support/fixtures.ex

28 lines
802 B
Elixir

defmodule Asciinema.Fixtures do
alias Asciinema.{Repo, Asciicasts, 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",
auth_token: "authy-auth-auth"}, attrs)
Repo.insert!(User.changeset(%User{}, attrs))
end
def fixture(:asciicast, _attrs) do
user = fixture(:user)
upload = fixture(:upload)
{:ok, asciicast} = Asciicasts.create_asciicast(user, upload)
asciicast
end
end