如何使用FactoryGirl创建一个名为“method”的属性?

时间:2014-10-17 01:33:50

标签: ruby-on-rails ruby factory-bot

如果method和self.method是保留字,如何创建FactoryGirl实例?

FactoryGirl.define do
  factory :payment do
    method 'paypal' # self.method doesn't work as well
    amount 12.95
  end
end

1 个答案:

答案 0 :(得分:0)

您需要add_attribute方法,但@ user3946015提到的语法似乎不适用于FactoryGirl 4.5.0。而是尝试:

add_attribute(:method) { 'paypal' }