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", ... }
精彩评论