Created
January 9, 2016 15:00
-
-
Save terakilobyte/c20b43f829cd709d8b26 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 Votio.TopicTest do | |
use Votio.ModelCase | |
import Votio.TestHelpers, only: [insert_topic: 1] | |
alias Votio.Topic | |
@valid_attrs %{categories: %{option1: 0, option2: 0}, title: "some content"} | |
@invalid_attrs1 %{} | |
@invalid_attrs2 %{title: "nope", categories: %{scotch: 0, beer: 0}} | |
@invalid_attrs3 %{title: "long enough but no categories"} | |
@invalid_attrs4 %{title: "valid title but one category", category: %{nope: 0}} | |
test "changeset with valid attributes" do | |
changeset = Topic.changeset(%Topic{}, @valid_attrs) | |
assert changeset.valid? | |
end | |
test "changeset with no attributes" do | |
changeset = Topic.changeset(%Topic{}, @invalid_attrs1) | |
refute changeset.valid? | |
end | |
test "changeset with title too short" do | |
changeset = Topic.changeset(%Topic{}, @invalid_attrs2) | |
refute changeset.valid? | |
end | |
test "changeset with no categories" do | |
changeset = Topic.changeset(%Topic{}, @invalid_attrs3) | |
refute changeset.valid? | |
end | |
test "changeset with only 1 category" do | |
changeset = Topic.changeset(%Topic{}, @invalid_attrs4) | |
refute changeset.valid? | |
end | |
test "changeset is invalid with existing topic title" do | |
insert_topic(@valid_attrs) | |
case insert_topic(@valid_attrs) do | |
{:error, changeset} -> | |
refute changeset.valid? | |
_ -> | |
refute true # this will always fail, we should never hit this | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment