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

Version Path
workarea-core-3.5.27 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.26 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.25 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.23 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.22 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.21 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.20 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.19 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.18 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.17 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.16 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.15 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.14 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.13 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.12 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.11 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.10 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.9 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.8 test/lib/workarea/ext/mongoid/embedded_children_test.rb
workarea-core-3.5.7 test/lib/workarea/ext/mongoid/embedded_children_test.rb