Created
October 9, 2016 14:34
-
-
Save harfangk/6ee25f8e760fe7fa1e9f52d8ed79d108 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 Rumbl.UserTest do | |
use Rumbl.ModelCase, async: true | |
alias Rumbl.User | |
@valid_attrs %{name: "A User", username: "eva", password: "secret"} | |
@invalid_attrs %{} | |
test "changeset with valid attributes" do | |
changeset = User.changeset(%User{}, @valid_attrs) | |
assert changeset.valid? | |
end | |
test "changeset with invalid characters" do | |
changeset = User.changeset(%User{}, @invalid_attrs) | |
refute changeset.valid? | |
end | |
test "changeset does not accept long usernames" do | |
attrs = Map.put(@valid_attrs, :username, String.duplicate("a", 30)) | |
assert {:username, {"should be at most %{count} character(s)", [count: 20]}} in | |
errors_on(%User{}, attrs) | |
end | |
test "registration_changeset password must be at least 6 characters long" do | |
attrs = Map.put(@valid_attrs, :password, "12345") | |
changeset = User.registration_changeset(%User{}, attrs) | |
assert {:password, {"should be at least %{count} character(s)", count: 6}} in changeset.errors | |
end | |
test "registration_changeset with valid attributes hashes password" do | |
attrs = Map.put(@valid_attrs, :password, "123456") | |
changeset = User.registration_changeset(%User{}, attrs) | |
%{password: pass, password_hash: pass_hash} = changeset.changes | |
assert changeset.valid? | |
assert pass_hash | |
assert Comeonin.Bcrypt.checkpw(pass, pass_hash) | |
end | |
end | |
============================================= | |
test result: | |
1) test changeset does not accept long usernames (Rumbl.UserTest) │~ | |
test/models/user_test.exs:18 │~ | |
Assertion with in failed │~ | |
code: {:username, {"should be at most %{count} character(s)", [count: 20]}} in errors_on(%User{}, attrs) │~ | |
lhs: {:username, {"should be at most %{count} character(s)", [count: 20]}} │~ | |
rhs: [username: "should be at most 20 character(s)"] │~ | |
stacktrace: │~ | |
test/models/user_test.exs:20: (test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment