(Note: The reason I'm making the issue here is because Mongoid works normally according to my console testing.)
My Fabrication for Account:
Fabricator(:account) do
email { Forgery(:internet).email_address }
password { Forgery(:basic).password(:at_least => 8, :at_most => 256) }
name { Forgery(:name).full_name }
age { Forgery(:basic).number(:at_least => 13, :at_most => 80) }
terms true
links :count => 10
end
My Links fabrication:
Fabricator(:link) do
title { Forgery(:lorem_ipsum).words(rand(7) + 2) }
url {
domain = Forgery(:internet).domain_name
path = Forgery(:lorem_ipsum).words(rand(3) + 1).gsub(/\s/,'/')
extention = ["index.html", "file.pdf", ""].random
"http://#{domain}/#{path}/#{extention}"}
end
Creating these objects works without problem:
:014 > Fabricate(:account)
=> #<Account _id: 4e62fcb1a53b22767600000c, _type: "Account", created_at: 2011-09-04 04:21:05 UTC, updated_at: 2011-09-04 04:21:05 UTC, deleted_at: nil, version: 1, email: "[email protected]", password: "$2a$10$MiISQ5y4eZLjqjChexdi2ewQurYcdnCDb.P.b4SD0UtBWlW5jDCpW", name: "Carolyn Edwards", age: 61, admin: false, support: false, terms: true, banned: false, disabled: false>
:016 > Fabricate(:link)
=> #<Link _id: 4e62fceea53b227676000017, _type: "Link", created_at: 2011-09-04 04:22:06 UTC, updated_at: 2011-09-04 04:22:06 UTC, deleted_at: nil, version: 1, title: "lorem ipsum", url: "http://avaveo.biz/lorem/file.pdf", dead: false, account_id: nil>
Creating these objects without Fabrication and associating them works without problem:
:017 > account = Account.new Fabricate.attributes_for :account
=> #<Account _id: 4e62fd21a53b227676000023, _type: "Account", created_at: nil, updated_at: nil, deleted_at: nil, version: 1, email: "[email protected]", password: "X0wvvXui3iLydnWCMxSP53sd3fZCwn1zVURYDXCKjFNwAOLHeoR0ZfEESXxTe7e3N9P3lzFtY0UdtLogYHUIBAAECb0Wy3mEnLJlB1nmAg1Xe8mwQfTaGgTQf4uccW87Sa48QcIo5hhxtqZ4jAlgPBTTsPiLQGzg7DQ6BHBFUNg6Iq2Lgnhy1yiqNeRz3nwlO1wLBQdfaLbpJAmrFnQNbF1nvE4YL4Akspr", name: "Harold Anderson", age: 13, admin: false, support: false, terms: true, banned: false, disabled: false>
:018 > link = Link.new Fabricate.attributes_for :link
=> #<Link _id: 4e62fd31a53b227676000025, _type: "Link", created_at: nil, updated_at: nil, deleted_at: nil, version: 1, title: "lorem ipsum dolor sit amet consectetuer adipiscing", url: "http://yotz.net/lorem/", dead: false, account_id: nil>
:019 > account.links << link
=> [#<Link _id: 4e62fd31a53b227676000025, _type: "Link", created_at: nil, updated_at: nil, deleted_at: nil, version: 1, title: "lorem ipsum dolor sit amet consectetuer adipiscing", url: "http://yotz.net/lorem/", dead: false, account_id: BSON::ObjectId('4e62fd21a53b227676000023')>]
:020 > account.links
=> [#<Link _id: 4e62fd31a53b227676000025, _type: "Link", created_at: nil, updated_at: nil, deleted_at: nil, version: 1, title: "lorem ipsum dolor sit amet consectetuer adipiscing", url: "http://yotz.net/lorem/", dead: false, account_id: BSON::ObjectId('4e62fd21a53b227676000023')>]
:021 > account.save
=> true
:022 > link.save
=> true
:023 > account.reload
=> #<Account _id: 4e62fd21a53b227676000023, _type: "Account", created_at: 2011-09-04 04:23:31 UTC, updated_at: 2011-09-04 04:23:31 UTC, deleted_at: nil, version: 1, email: "[email protected]", password: "$2a$10$C8Q8gHi2c4hR3QwW86pSPuGWGr7ZcF70n9X0ZZGUrTNGUCyPEsf9O", name: "Harold Anderson", age: 13, admin: false, support: false, terms: true, banned: false, disabled: false>
:024 > account.links
=> [#<Link _id: 4e62fd31a53b227676000025, _type: "Link", created_at: 2011-09-04 04:23:34 UTC, updated_at: 2011-09-04 04:23:34 UTC, deleted_at: nil, version: 1, title: "lorem ipsum dolor sit amet consectetuer adipiscing", url: "http://yotz.net/lorem/", dead: false, account_id: BSON::ObjectId('4e62fd21a53b227676000023')>]
And now to check relations with the Fabrication creation:
:027 > Account.count
=> 0
:028 > Link.count
=> 0
:029 > account = Fabricate(:account)
=> #<Account _id: 4e62fd96a53b227676000026, _type: "Account", created_at: 2011-09-04 04:24:54 UTC, updated_at: 2011-09-04 04:24:54 UTC, deleted_at: nil, version: 1, email: "[email protected]", password: "$2a$10$qr.IcMyXes2s4wr70BOrPeEUdAXtL17.6DB9AvZAAU/LvPstAHGFC", name: "Ruby Mcdonald", age: 20, admin: false, support: false, terms: true, banned: false, disabled: false>
:030 > account.links
=> []
:031 > account.links.first
=> #<Link _id: 4e62fd96a53b227676000027, _type: "Link", created_at: 2011-09-04 04:24:54 UTC, updated_at: 2011-09-04 04:24:54 UTC, deleted_at: nil, version: 1, title: "lorem ipsum", url: "http://zoomlounge.edu/lorem/file.pdf", dead: false, account_id: BSON::ObjectId('4e62fd96a53b227676000026')>
:032 > account.links.last
=> #<Link _id: 4e62fd96a53b227676000030, _type: "Link", created_at: 2011-09-04 04:24:54 UTC, updated_at: 2011-09-04 04:24:54 UTC, deleted_at: nil, version: 1, title: "lorem ipsum dolor sit amet consectetuer adipiscing", url: "http://feednation.org/lorem/ipsum/dolor/", dead: false, account_id: BSON::ObjectId('4e62fd96a53b227676000026')>
:033 > Account.count
=> 1
:034 > Link.count
=> 10
How strange is that?