Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MONGOID-5808 Fix collection_options in store_in #5859

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Metrics/MethodLength:
RSpec/BeforeAfterAll:
Enabled: false

RSpec/DescribeClass:
Enabled: false

RSpec/ImplicitExpect:
EnforcedStyle: is_expected

Expand Down
3 changes: 2 additions & 1 deletion lib/mongoid/persistence_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class PersistenceContext
# @return [ Array<Symbol> ] The list of extra options besides client options
# that determine the persistence context.
EXTRA_OPTIONS = [ :client,
:collection
:collection,
:collection_options
].freeze

# The full list of valid persistence context options.
Expand Down
36 changes: 36 additions & 0 deletions spec/integration/persistence/collection_options_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require 'spec_helper'

# rubocop:disable RSpec/LeakyConstantDeclaration
# rubocop:disable Lint/ConstantDefinitionInBlock
describe 'Collection options' do
before(:all) do
class CollectionOptionsCapped
include Mongoid::Document

store_in collection_options: {
capped: true,
size: 25_600
}
end
end

after(:all) do
CollectionOptionsCapped.collection.drop
Mongoid.deregister_model(CollectionOptionsCapped)
Object.send(:remove_const, :CollectionOptionsCapped)
end

before do
CollectionOptionsCapped.collection.drop
# We should create the collection explicitly to apply collection options.
CollectionOptionsCapped.create_collection
end

it 'creates a document' do
expect { CollectionOptionsCapped.create! }.not_to raise_error
end
end
# rubocop:enable Lint/ConstantDefinitionInBlock
# rubocop:enable RSpec/LeakyConstantDeclaration
2 changes: 1 addition & 1 deletion spec/mongoid/monkey_patches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# @note This test ensures that we do not inadvertently introduce new monkey patches
# to Mongoid. Existing monkey patch methods which are marked with +Mongoid.deprecated+
# are excluded from this test.
RSpec.describe('Do not add monkey patches') do # rubocop:disable RSpec/DescribeClass
RSpec.describe('Do not add monkey patches') do
classes = [
Object,
Array,
Expand Down
21 changes: 17 additions & 4 deletions spec/mongoid/persistence_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,25 @@

context 'when the options are valid extra options' do

let(:options) do
{ collection: 'other' }
context 'collection' do

let(:options) do
{ collection: 'other' }
end

it 'sets the options on the persistence context object' do
expect(persistence_context.collection_name).to eq(options[:collection].to_sym)
end
end

it 'sets the options on the persistence context object' do
expect(persistence_context.collection_name).to eq(options[:collection].to_sym)
context 'collection_options' do
let(:options) do
{ collection_options: { capped: true } }
end

it 'does not propagate to client options' do
expect(persistence_context.send(:client_options).key?(:collection_options)).to eq(false)
end
end
end

Expand Down
Loading