ruby-on-rails – FactoryGirl瞬态变量的未定义方法
发布时间:2020-12-16 20:09:07 所属栏目:百科 来源:网络整理
导读:我正在使用FactoryGirl 4.4版.我正在尝试创建after(:create)回调,但是我在评估器变量上失败. FactoryGirl.define do factory :organization do name 'example' factory :organization_with_links do transient do links_count 5 end after(:create) do |org
我正在使用FactoryGirl 4.4版.我正在尝试创建after(:create)回调,但是我在评估器变量上失败.
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 不幸的是我得到了 NoMethodError: undefined method `links_count' for FactoryGirl::SyntaxRunner:0x007fcefb1ff780> 根据officall工厂女孩指导我正在做的一切正常:https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations 任何建议如何使瞬态变量工作? 解决方法
所以解决办法是改变
transient do links_count 5 end 至 ignore do links_count 5 end 原因:在MasterGirl v.5.0上准备了主文件.暂时会在5.0版本上发布. 更多阅读:http://github.com/thoughtbot/factory_girl/issues/658 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |