【发布时间】:2016-05-21 22:18:51
【问题描述】:
我是灵药新手,所以不要太苛刻 我有以下型号:
defmodule MyApp.Device do
use MyApp.Web, :model
schema "devices" do
field :name, :string
belongs_to :user, MyApp.User
timestamps
end
end
defmodule MyApp.User do
use MyApp.Web, :model
schema "users" do
field :name, :string
has_many :devices, MyApp.Device
timestamps
end
end
我如何以优雅的方式测试用户拥有许多设备。比如
test "registration generates user with devices" do
changeset = Registration.changeset(%Registration{}, @valid_attrs)
registration = Ecto.Changeset.apply_changes(changeset)
user = Registration.to_user(changeset)
IO.puts "#{inspect user}"
# assert device is inside the user
end
【问题讨论】:
-
您引用的 Typi 是什么? Typi.User 和 Typi.Device?我的意思是我猜某个地方有一个 Typi 模块,但它是你的吗?
-
您可能会发现 Elixir Talk Google Group 的对话内容也值得一读:groups.google.com/forum/#!topic/elixir-ecto/BKpLf092dWs
-
@OnorioCatenacci 已更改为 MyApp :) 忘记重命名内容。我试图隐藏名字
-
@OnorioCatenacci 感谢您的链接,良好的指导方针
标签: unit-testing testing tdd elixir ecto