Sha256: 722a4b1b1829d52a9a8d8db84cd6b07cf8d30648907408e5e5b80405ad46d4b7
Contents?: true
Size: 958 Bytes
Versions: 27
Compression:
Stored size: 958 Bytes
Contents
require 'test_helper' module Mongoid class EmbeddedChildrenTest < Workarea::TestCase class Parent include Mongoid::Document embeds_one :child, class_name: 'Mongoid::EmbeddedChildrenTest::Child' embeds_many :children, class_name: 'Mongoid::EmbeddedChildrenTest::Child' end class Child include Mongoid::Document field :name, type: String embeds_one :grandchild, class_name: 'Mongoid::EmbeddedChildrenTest::Grandchild' embeds_many :grandchildren, class_name: 'Mongoid::EmbeddedChildrenTest::Grandchild' end class Grandchild include Mongoid::Document field :name, type: String end def test_embedded_children model = Parent.create!( child: { name: '1', grandchild: { name: '2' } }, children: [{ name: '3' }, { name: '4', grandchildren: [{ name: '5' }] }] ) assert_equal(%w(1 2 3 4 5), model.embedded_children.map(&:name)) end end end
Version data entries
27 entries across 27 versions & 1 rubygems