Skip to content

Instantly share code, notes, and snippets.

@ybur-yug
Last active January 27, 2017 17:37
Show Gist options
  • Save ybur-yug/b8ceafee949dc6dfa9d2bd3a8e037557 to your computer and use it in GitHub Desktop.
Save ybur-yug/b8ceafee949dc6dfa9d2bd3a8e037557 to your computer and use it in GitHub Desktop.
defmodule Services.SchemaCase do
use ExUnit.CaseTemplate
using(opts) do
quote bind_quoted: [opts: opts] do
alias Services.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query
import Services.SchemaCase
@schema opts[:schema]
@struct opts[:struct]
@valid_attrs opts[:valid_attributes]
@invalid_attrs opts[:invalid_attributes]
test "changeset with valid attributes" do
changeset = @schema.changeset(@struct, @valid_attrs)
assert changeset.valid?
end
test "changeset with invalid attributes" do
changeset = @schema.changeset(@struct, @invalid_attrs)
refute changeset.valid?
end
end
end
end
defmodule Services.Schema.User do
use Services.SchemaCase,
valid_attributes: %{name: "Freeeeee",
gem_version: "1.01"},
invalid_attributes: %{foo: "buz"},
schema: Services.Schema.User,
struct: %Services.Schema.User{}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment