I'm having trouble with what looks like a very simple problem.
So I have 3 models: Foo, Bar, and Lol
- Foo has_many Bars
- Lol has_many Bars
- Bar belongs_to Foo & Lol
Here's the code that's giving me errors.
spec/factories/foos.rb
FactoryGirl.define do
factory :foo do
after(:create) do |foo|
create_list(:bar, 1, foo: foo)
end
end
end
spec/factories/bars.rb
FactoryGirl.define do
factory :bar do
foo
lol
end
end
spec/factories/lols.rb
FactoryGirl.define do
factory :lol do
after(:create) do |lol|
create_list(:bar, 1, lol: lol)
end
end
end
I'm trying to get this test to pass
spec/models/foo_spec.rb
require 'spec_helper'
describe Foo do
it "works" do
foo = FactoryGirl.create(:foo)
puts foo.bars
foo.bars.each {|bar| puts bar.lol}
foo.should_not be_nil
end
end