|
8 | 8 |
|
9 | 9 | context 'when the document is a root document' do |
10 | 10 |
|
11 | | - context 'when setting the read preference to non-primary' do |
12 | | - |
13 | | - before do |
14 | | - Dictionary.validates_uniqueness_of :name |
15 | | - end |
16 | | - |
17 | | - after do |
18 | | - Dictionary.reset_callbacks(:validate) |
19 | | - end |
20 | | - |
21 | | - it 'reads from the primary' do |
22 | | - expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs| |
23 | | - crit = m.call(*args, **kwargs) |
24 | | - expect(crit.view.options['read']).to eq({ 'mode' => :primary }) |
25 | | - crit |
26 | | - end |
27 | | - Dictionary.with(read: { mode: :secondary }) do |klass| |
28 | | - klass.create!(name: 'Websters') |
29 | | - end |
30 | | - end |
31 | | - end |
32 | | - |
33 | 11 | context 'when adding custom persistence options' do |
34 | 12 |
|
35 | 13 | before do |
|
1653 | 1631 | word.definitions.create!(description: '2') |
1654 | 1632 | end |
1655 | 1633 |
|
1656 | | - context 'when setting the read preference to non-primary' do |
1657 | | - |
1658 | | - before do |
1659 | | - Definition.validates_uniqueness_of :description |
1660 | | - end |
1661 | | - |
1662 | | - after do |
1663 | | - Definition.reset_callbacks(:validate) |
1664 | | - end |
1665 | | - |
1666 | | - let(:word) { Word.create! } |
1667 | | - |
1668 | | - it 'reads from the primary' do |
1669 | | - expect_any_instance_of(Mongoid::Criteria).to receive(:read).once.and_wrap_original do |m, *args, **kwargs| |
1670 | | - crit = m.call(*args, **kwargs) |
1671 | | - expect(crit.options[:read]).to eq({ mode: :primary }) |
1672 | | - crit |
1673 | | - end |
1674 | | - Definition.with(read: { mode: :secondary }) do |
1675 | | - word.definitions.create! |
1676 | | - end |
1677 | | - end |
1678 | | - end |
1679 | | - |
1680 | 1634 | context 'when a document is being destroyed' do |
1681 | 1635 |
|
1682 | 1636 | before do |
|
0 commit comments