factory_girl_elixir
factory_girl_elixir copied to clipboard
Can't reference a factory from another factory definition
Hi there,
perhaps it might be my fault, but it I wasn't able to reference a factory from another definition. This is a common use case, for example when you want create a record on the fly to associate to another factory.
to quickly test this, I've modified your test/factory_girl_elixir_test.exs this way:
[...]
factory :user do
field :name, "joe"
field :password, "secret"
field :email, &("foo#{&1}@example.com")
# getting a value through another factory
field :asset_name, fn(_) ->
assets = Factory.attributes_for(:assets) |> Factory.parametrize
assets.name
end
end
factory :assets do
field :name, "bob"
end
[...]
when I run mix test I get this:
=ERROR REPORT==== 7-Sep-2015::23:00:32 ===
** Generic server factory_girl terminating
** Last message in was {get,user,[]}
** When Server state == [{counters,[]},
{attributes,
[{assets,[{name,<<"bob">>}]},
{user,
[{asset_name,
#Fun<elixir_compiler_2.1.33695206>},
{email,#Fun<elixir_compiler_2.0.33695206>},
{password,<<"secret">>},
{name,<<"joe">>}]}]}]
** Reason for termination ==
** {{timeout,{'Elixir.GenServer',call,[factory_girl,{get,assets,[]},5000]}},
[{'Elixir.GenServer',call,3,[{file,"lib/gen_server.ex"},{line,356}]},
{elixir_compiler_2,'-__MODULE__/1-fun-1-',1,
[{file,"test/factory_girl_elixir_test.exs"},{line,12}]},
{'Elixir.FactoryGirlElixir.Worker',expand_functions,3,
[{file,"lib/factory_girl_elixir/worker.ex"},{line,60}]},
{'Elixir.FactoryGirlElixir.Worker',handle_call,3,
[{file,"lib/factory_girl_elixir/worker.ex"},{line,45}]},
{gen_server,try_handle_call,4,[{file,"gen_server.erl"},{line,629}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,661}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
of course, the tests are broken.
Any hint or workaround for this? :-P