Sha256: 7fd485ad3a66bc0a7fedb55b1e835a9358e69065caaa8540b995344e714486ca

Contents?: true

Size: 1.51 KB

Versions: 26

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require_relative '../../mongoid/association/embedded/embeds_many_models'
require_relative '../../mongoid/association/embedded/embeds_one_models'

describe 'embedded associations' do
  describe 'dirty tracking' do
    context 'when association is cyclic' do
      before do
        # create deeply nested record
        a = EmmOuter.create(level: 0)
        level = 1
        iter = a.inners.create(level: level)
        loop do
          iter.friends.create(level: (level += 1))
          iter = iter.friends[0]
          break if level == 40
        end
      end

      let(:subject) { EmmOuter.first }

      it 'performs dirty tracking efficiently' do
        subject.changed?.should be false
      end

      it 'calculates the descendants properly' do
        expect(subject._descendants.length).to eq(40)
      end
    end

    context 'when association is cyclic and the _id is nil' do
      before do
        # create deeply nested record
        a = EmmOuter.create(level: 0)
        level = 1
        iter = a.inners.create(id: nil, level: level)
        loop do
          iter.friends.create(id: nil, level: (level += 1))
          iter = iter.friends[0]
          break if level == 40
        end
      end

      let(:subject) { EmmOuter.first }

      it 'performs dirty tracking efficiently' do
        subject.changed?.should be false
      end

      it 'calculates the descendants properly' do
        expect(subject._descendants.length).to eq(40)
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mongoid-8.1.9 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.9 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.8 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.7 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.6 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.8 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.5 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.4 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.7 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.3 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.2 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.6 spec/integration/associations/embedded_dirty_spec.rb
mongoid-7.5.4 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.1 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.5 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.1.0 spec/integration/associations/embedded_dirty_spec.rb
mongoid-7.5.3 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.4 spec/integration/associations/embedded_dirty_spec.rb
mongoid-8.0.3 spec/integration/associations/embedded_dirty_spec.rb
mongoid-7.5.2 spec/integration/associations/embedded_dirty_spec.rb