-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathdocument_spec.rb
52 lines (42 loc) · 1.23 KB
/
document_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
# rubocop:todo all
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
context 'when id is unaliased' do
it 'persists separate id and _id values' do
shirt = Shirt.create!(id: 'hello', _id: 'foo')
shirt = Shirt.find(shirt._id)
shirt.id.should == 'hello'
shirt._id.should == 'foo'
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