There aren't currently any up to date answers for this using Factory Girl 4.1 (that I could find) - how do you setup a many to many relationship inside of a factory?
For instance I have Students and Classrooms which are in a many to many relationship using a join table, so far I had the following setup:
factory :classroom do
name "Foo Class"
...
end
factory :student do
name "John Doe"
...
end
factory :student_with_classroom, :parent => :student do
after(:build) {|student| student.classrooms << classroom}
end
However this results in:
NameError:
undefined local variable or method `classroom' for #<FactoryGirl::SyntaxRunner>
My attempt was guesswork for the most part as I had no luck finding any non-deprecated syntax to accomplish this.