Undefined methods for FactoryGirl transient variables

蹲街弑〆低调 提交于 2019-11-30 21:57:35

问题


I'm working with FactoryGirl in version 4.4. I'm trying to create after(:create) callbacks but I'm failing on evaluator variables.

FactoryGirl.define do
  factory :organization do

    name 'example'

    factory :organization_with_links do

      transient do
        links_count 5
      end

      after(:create) do |organization, evaluator|
        create_list(:link, evaluator.links_count, organization: organization)
      end
    end
  end
end

unfortunately I got

NoMethodError: undefined method `links_count' for  FactoryGirl::SyntaxRunner:0x007fcefb1ff780>

according to officall factory girl guide I'm doing everything properly :https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations

any advices how to make transient variable working?


回答1:


So the solution was to change

transient do
   links_count 5
end

to

ignore do
  links_count 5
end

Reason: Docs on master are prepared for FactoryGirl v.5.0. transient will wok on 5.0 release.

More reading: http://github.com/thoughtbot/factory_girl/issues/658



来源:https://stackoverflow.com/questions/25510268/undefined-methods-for-factorygirl-transient-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!