Last active
August 29, 2015 14:20
-
-
Save nessamurmur/81281be8ddfd976b7566 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 MyApp.User do | |
alias MyApp.Repo | |
## Stuff omitted | |
def changeset(model, params) do | |
model | |
|> cast(params, @required_fields, @optional_fields) | |
|> validate_unique(:username, on: Repo) | |
end | |
end | |
defmodule MyApp.UserTest do | |
# Stuff omitted | |
@valid_attrs %{username: "thedude"} | |
test "validates uniqueness of username" do | |
changeset = User.changeset(%User{}, @valid_attrs) | |
Repo.insert(changeset) | |
refute changeset.valid? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment