Sha256: 8bf73a40885d31f0de972924466ff748d30d286045afdec736d3d3025a6eb5da

Contents?: true

Size: 1007 Bytes

Versions: 9

Compression:

Stored size: 1007 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

require 'spec_helper'

describe Mongoid::Document do
  context 'when including class uses delegate' do
    let(:patient) do
      DelegatingPatient.new(
        email: Email.new(address: 'test@example.com'),
      )
    end

    it 'works for instance level delegation' do
      patient.address.should == 'test@example.com'
    end

    it 'works for class level delegation' do
      DelegatingPatient.default_client.should be Mongoid.default_client
    end
  end

  describe '#reload' do
    context 'when changing shard key value' do
      require_topology :sharded

      let(:profile) do
        # Profile shard_key :name
        Profile.create!(name: "Alice")
      end

      it "successfully reloads the document after saving an update to the sharded field" do
        expect(profile.name).to eq("Alice")
        profile.name = "Bob"
        profile.save!

        profile.reload

        expect(profile.name).to eq("Bob")
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongoid-7.1.11 spec/integration/document_spec.rb
mongoid-7.2.6 spec/integration/document_spec.rb
mongoid-7.2.5 spec/integration/document_spec.rb
mongoid-7.1.10 spec/integration/document_spec.rb
mongoid-7.1.9 spec/integration/document_spec.rb
mongoid-7.2.4 spec/integration/document_spec.rb
mongoid-7.2.3 spec/integration/document_spec.rb
mongoid-7.1.8 spec/integration/document_spec.rb
mongoid-7.2.2 spec/integration/document_spec.rb