开发者

Factory Girl: How do you make a factory that isn't tied to a model?

I just need a hash of attributes for things like credit card, and address. Example:

Factory.define :credit_card, :class => Object do |c|
  c.first_开发者_运维知识库name "Alice"
  c.last_name "Liddel"
  c.month "May"
  c.year { Time.now.year + 1 }
  c.number "1234567812345678"
  c.type "Visa"
  c.verification_value "123"
end

obviously, object doesn't have any attributes, and I don't have a credit_cord object... I just need a standard credit card skeleton.


What is the advantage of using factory girl for this? How about a helper method:

def credit_card(attrs = {})
   {
     :first_name => "Alice",
     ...,
     :verification_value => "123"
   }.with_indifferent_access.merge(attrs)
end

credit_card :first_name => "Linda"   # returns { :first_name => "Linda", :last_name => "Liddel", ... }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜