Skip to content

Commit c2d6223

Browse files
MONGOID-5808 Fix collection_options in store_in
1 parent 69eaf1d commit c2d6223

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Metrics/MethodLength:
7575
RSpec/BeforeAfterAll:
7676
Enabled: false
7777

78+
RSpec/DescribeClass:
79+
Enabled: false
80+
7881
RSpec/ImplicitExpect:
7982
EnforcedStyle: is_expected
8083

lib/mongoid/persistence_context.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class PersistenceContext
2525
# @return [ Array<Symbol> ] The list of extra options besides client options
2626
# that determine the persistence context.
2727
EXTRA_OPTIONS = [ :client,
28-
:collection
28+
:collection,
29+
:collection_options
2930
].freeze
3031

3132
# The full list of valid persistence context options.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

spec/mongoid/persistence_context_spec.rb

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,25 @@
206206

207207
context 'when the options are valid extra options' do
208208

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
211218
end
212219

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
215228
end
216229
end
217230

0 commit comments

Comments
 (0)