我在我的系统中做了很大的修改,所以我将我的一个主表更改为STI,并创建子类来实现特定的行为。但是在Rspec测试中,当我运行FactoryBot::create(:main_process, type: 'ProcessA')时,它返回一个MainProcess并破坏了我的测试。我的因素是这样的 factory :main_process do end
factory :process_aProcessA
我在Rspec on rails中使用FactoryBot。/app/models/specific_keyword.rb:19:in `initialize'
看起来,当使用SpecificKeyword实例化FactoryBot时,不向init方法传递args这是一种理想的行为吗?如果是这样的话,我应该如何继续在测试中继续使用FactoryBot?当我只做SpecificKeyword.new(name:'Test')的时候,它确实起作用了。
在我的模型中,我有一些上下文验证: validate :permissions, on :admin
error.add(:permissions, 'Must be set as admin') unless permissions.include? :admin enduser.save(context: :admin)
问题是:如何检查验证是否通过admin上下文通过factory_girl运行?create :user, context: :admin不起作用