-
-
Save ryana/29d464f1c3f8cd6f6f2e 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' | |
Mongoid.configure do |config| | |
config.connect_to('test') | |
end | |
class Room | |
include Mongoid::Document | |
has_one :table, as: :parent, autobuild: true | |
after_create :ensure_table | |
def ensure_table | |
table.save! | |
end | |
end | |
class Table | |
include Mongoid::Document | |
belongs_to :parent, polymorphic: true | |
embeds_many :chairs | |
end | |
class Chair | |
include Mongoid::Document | |
embedded_in :table | |
end | |
n = Table.count | |
m = 4 | |
@room = Room.create! | |
@table = @room.table | |
@table.reload | |
m.times{ @table.chairs << Chair.new } | |
abort 'blargh' unless(Table.count == n + 1) | |
abort 'blurgh' unless(@table.chairs.size == m) | |
abort 'blurghy!' unless(Table.first.chairs.size == m) | |
puts Mongoid::VERSION #=> 3.1.6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment