I am implementing Factory Girl as a replacement for fixtures in my Rails application. I have several tables that I'm trying to represent using associations. However, in order to throw a loop into the loop, in addition to simply defining associations, I also need to access the attributes of the subsidiary factories from the parent.
Below is an example of what I'm trying to do:
- Factory: foo_bar related to Factory: foo related to Factory: bar
- From: foo_bar, I'm trying to access the attributes of both: foo and: bar
Here are some examples:
Factory.define :bar do |e|
e.name "Bar"
end
Factory.define :foo do |e|
e.bar {|b| b.association(:bar)}
end
Factory.define :foo_bar do |b|
f = b.association(:foo)
b.foo_id foo.id
b.bar_id foo.bar_id
end
I looked through a number of lessons and other questions and did not see examples of how to do this. Any ideas or other ways to get the same result?
Thank!
EDIT
, , ...
: foo_bar - , .
, :
- have: foo_bar Factory
- Factory Factory
- ( , ): foo_bar Factory
, : foo_bar > : foo > : bar, : foo_bar, : bar ID.