Skip to content

Commit 370d748

Browse files
committed
RUBY-1082 Account for when write concern is nil in GridFS write stream
1 parent 1c1991d commit 370d748

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/mongo/grid/stream/write.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ def files_collection
157157
end
158158

159159
def with_write_concern(collection)
160-
if collection.write_concern.options == write_concern.options
160+
if write_concern.nil? || collection.write_concern.nil? ||
161+
collection.write_concern.options == write_concern.options
161162
collection
162163
else
163164
collection.client.with(write: write_concern.options)[collection.name]

spec/mongo/grid/stream/write_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@
6666
end
6767
end
6868

69+
context 'when the fs does not have a write concern' do
70+
71+
let(:fs) do
72+
authorized_client.with(write: nil).database.fs
73+
end
74+
75+
it 'uses the write concern default at the operation level' do
76+
expect(stream.write(file).closed?).to eq(false)
77+
end
78+
end
79+
6980
context 'when provided options' do
7081

7182
context 'when provided a write option' do

0 commit comments

Comments
 (0)