Last active
January 27, 2017 17:37
-
-
Save ybur-yug/b8ceafee949dc6dfa9d2bd3a8e037557 to your computer and use it in GitHub Desktop.
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
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 |
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
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