Skip to content

Instantly share code, notes, and snippets.

@karlosmid
Last active May 17, 2020 16:46
Show Gist options
  • Save karlosmid/9a046c059851b99686403621c44a2467 to your computer and use it in GitHub Desktop.
Save karlosmid/9a046c059851b99686403621c44a2467 to your computer and use it in GitHub Desktop.
defmodule Testivator.CRM.DatafileSpec do
@moduledoc """
This module holds espec spec demonstrations for CRM.Datafile module.
"""
use ESpec.Phoenix, async: false, model: DataFile
alias Testivator.CRM.DataFile
alias Testivator.File
import Mock
context "Changeset" do
it "connection timeout" do
file = %Plug.Upload{
content_type: "application/pdf",
filename: "document.pdf",
path: Plug.Upload.random_file!(".pdf")}
changeset = DataFile.changeset(%DataFile{}, %{inserted_at: "none", file: file})
expect(to(changeset.valid?, be_truthy()))
expect(to(changeset.changes.file.file_name, eq(file)))
end
it "valid attributes" do
file = %Plug.Upload{
content_type: "application/pdf",
filename: "document.pdf",
path: Plug.Upload.random_file!(".pdf")}
with_mock(File, [
store: fn
({file, _}) -> {:ok, file}
end
]) do
changeset = DataFile.changeset(%DataFile{}, %{inserted_at: "none", file: file})
expect(to(changeset.valid?, be_truthy()))
expect(to(changeset.changes.file.file_name, eq(file)))
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment