   defmodule Factory do
     use ExMachina.Ecto, repo: TestRepo
 
-    factory(:invalid_package) do
-      %Package{
-        description: "Invalid package without any statuses"
-      }
-    end
-
     factory(:package) do
       %Package{
         description: "Package that just got ordered",
         statuses: [
-          %PackageStatus{status: "ordered"}
+          build(:package_status, status: "ordered")
         ]
       }
     end

    end
  end

  test "create/1 creates model with `has_many` associations" do
    package = Factory.create(:package)

    assert %{statuses: [%{status: "ordered"}]} = package
  end

  test "create/2 creates model with overriden `has_many` associations" do
    statuses = [
      %PackageStatus{status: "ordered"},
      %PackageStatus{status: "delayed"}
    ]
    package = Factory.create :package,
      description: "Delayed package",
      statuses: statuses

    assert %{statuses: [%{status: "ordered"}, %{status: "delayed"}]} = package
  end

  test "create/1 creates model without `has_many` association specified" do
    package = Factory.create(:invalid_package)
    assert package
  end

  test "create/1 creates model with `belongs_to` having `has_many` associations" do
    invoice = Factory.create(:invoice)

    assert %{title: "Invoice for shipped package", package_id: 1} = invoice
  end
end

      %Package{
        description: "Package that got shipped",
        statuses: [
          build(:package_status, status: "ordered"),
          build(:package_status, status: "sent"),
          build(:package_status, status: "shipped")
        ]
      }
    end

    factory(:package_status) do
      %PackageStatus{
        status: "ordered"
      }
    end

