File tree Expand file tree Collapse file tree 4 files changed +57
-5
lines changed Expand file tree Collapse file tree 4 files changed +57
-5
lines changed Original file line number Diff line number Diff line change @@ -75,6 +75,9 @@ Metrics/MethodLength:
75
75
RSpec/BeforeAfterAll :
76
76
Enabled : false
77
77
78
+ RSpec/DescribeClass :
79
+ Enabled : false
80
+
78
81
RSpec/ImplicitExpect :
79
82
EnforcedStyle : is_expected
80
83
Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ class PersistenceContext
25
25
# @return [ Array<Symbol> ] The list of extra options besides client options
26
26
# that determine the persistence context.
27
27
EXTRA_OPTIONS = [ :client ,
28
- :collection
28
+ :collection ,
29
+ :collection_options
29
30
] . freeze
30
31
31
32
# The full list of valid persistence context options.
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # rubocop:disable RSpec/LeakyConstantDeclaration
6
+ # rubocop:disable Lint/ConstantDefinitionInBlock
7
+ describe 'Collection options' do
8
+ before ( :all ) do
9
+ class CollectionOptionsCapped
10
+ include Mongoid ::Document
11
+
12
+ store_in collection_options : {
13
+ capped : true ,
14
+ size : 25_600
15
+ }
16
+ end
17
+ end
18
+
19
+ after ( :all ) do
20
+ Mongoid . deregister_model ( CollectionOptionsCapped )
21
+ Object . send ( :remove_const , :CollectionOptionsCapped )
22
+ end
23
+
24
+ before do
25
+ CollectionOptionsCapped . collection . drop
26
+ # We should create the collection explicitly to apply collection options.
27
+ CollectionOptionsCapped . create_collection
28
+ end
29
+
30
+ it 'creates a document' do
31
+ expect { CollectionOptionsCapped . create! } . not_to raise_error
32
+ end
33
+ end
34
+ # rubocop:enable Lint/ConstantDefinitionInBlock
35
+ # rubocop:enable RSpec/LeakyConstantDeclaration
Original file line number Diff line number Diff line change 206
206
207
207
context 'when the options are valid extra options' do
208
208
209
- let ( :options ) do
210
- { collection : 'other' }
209
+ context 'collection' do
210
+
211
+ let ( :options ) do
212
+ { collection : 'other' }
213
+ end
214
+
215
+ it 'sets the options on the persistence context object' do
216
+ expect ( persistence_context . collection_name ) . to eq ( options [ :collection ] . to_sym )
217
+ end
211
218
end
212
219
213
- it 'sets the options on the persistence context object' do
214
- expect ( persistence_context . collection_name ) . to eq ( options [ :collection ] . to_sym )
220
+ context 'collection_options' do
221
+ let ( :options ) do
222
+ { collection_options : { capped : true } }
223
+ end
224
+
225
+ it 'does not propagate to client options' do
226
+ expect ( persistence_context . send ( :client_options ) . key? ( :collection_options ) ) . to eq ( false )
227
+ end
215
228
end
216
229
end
217
230
You can’t perform that action at this time.
0 commit comments