开发者

Factory-girl: 'association' named column overlap with Factory method named 'association'

开发者 https://www.devze.com 2023-03-30 15:26 出处:网络
I have the following Factory definition. Factory.define :status do |f| end Factory.define :my_status , :parent => :status do |f|

I have the following Factory definition.

Factory.define :status do |f|

end 

Factory.define :my_status , :parent => :status do |f|
  f.association 'something_here'
  f.alias 'something_here'
  f.name  'something_here'
end 

I know about the factory defined 'association' method, something like: f.association :group, :factory => :group But I actually have a column named association. What will be the way to assign values to my column?

Update: One way to solve came to me after Maletor's post - Thanks Maletor

I added this to my status model

  alias_attribute :assoc, :association 

and now I can do

Factory.define :my_status , :parent => :status do |f|
  f.assoc 'somthing_here'
  f.alias 'somthing_here'
  f.name  'somthin开发者_JAVA技巧g_here'
end

Works fine :)


You could assign it in an f.after_create. Not as elegant though. Renaming the column might not be a bad idea either.

0

精彩评论

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