Created
July 23, 2010 20:53
-
-
Save bernerdschaefer/488018 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'mongoid' | |
| require 'rspec' | |
| Mongoid.configure do |config| | |
| config.master = Mongo::Connection.new.db('testing') | |
| config.autocreate_indexes = true | |
| end | |
| class TaskGroupWorker | |
| include Mongoid::Document | |
| embedded_in :task_group, :inverse_of => :task_group_workers | |
| end | |
| class TaskGroup | |
| include Mongoid::Document | |
| embeds_many :task_group_workers | |
| collection.remove | |
| end | |
| task_group = TaskGroup.create | |
| worker = TaskGroupWorker.new | |
| task_group.task_group_workers << worker | |
| worker.save | |
| task_group.save | |
| TaskGroup.first.task_group_workers.size.should == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require 'mongoid'
require 'rspec'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db('testing')
config.autocreate_indexes = true
end
class TaskGroupWorker
include Mongoid::Document
embedded_in :task_group, :inverse_of => :task_group_workers
end
class TaskGroup
include Mongoid::Document
embeds_many :task_group_workers
collection.remove
end
task_group = TaskGroup.create
worker = TaskGroupWorker.new
task_group.task_group_workers << worker
worker.save
task_group.save
TaskGroup.first.task_group_workers.size.should == 1
TaskGroupWorker.count.should ==1