Q: Testing an OR validation I used the standard scaffold to create a user model with the attributes first_name and last_name. I wrote a validation which checks that first_name OR last_name are present. The default validation checks for an AND. What is the best way to add a test which tests that first_name or last_name are present?
defmodule Vutuv.UserTest do
  use Vutuv.ModelCase

  alias Vutuv.User

  @valid_attrs %{first_name: "some content", last_name: "some content"}
  @invalid_attrs %{}

  test "changeset with valid attributes" do
    changeset = User.changeset(%User{}, @valid_attrs)
    assert changeset.valid?
  end

  test "changeset with invalid attributes" do
    changeset = User.changeset(%User{}, @invalid_attrs)
    refute changeset.valid?
  end
end


A: I would make @valid_attrs a list with all valid combinations, and assert that all of them are valid in a test.
@valid_attrs [%{first_name: "some content", last_name: "some content"},
              %{first_name: "some content"},
              %{last_name: "some content"}]

test "changeset with valid attributes" do
  for valid_attrs <- @valid_attrs do
    changeset = User.changeset(%User{}, valid_attrs)
    assert changeset.valid?
  end
end

You could also create separate tests for each of them.
