Skip to content

Commit 52b652f

Browse files
Fix #destroy hanging after another action inside a transaction (#74)
* Fix #destroy hanging after another action inside a transaction * Add Rspecs
1 parent 5f46f41 commit 52b652f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/mongoid/paranoia.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def paranoid_field
190190
# @return [ Object ] Update result.
191191
#
192192
def _paranoia_update(value)
193-
paranoid_collection.find(atomic_selector).update_one(value)
193+
paranoid_collection.find(atomic_selector).update_one(value, session: _session)
194194
end
195195
end
196196
end

spec/mongoid/paranoia_spec.rb

+21
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,27 @@ class ParanoidConfiguredReset
318318
expect(post).not_to be_destroyed
319319
end
320320
end
321+
322+
context "when multiple operations wrapped inside transaction" do
323+
324+
let(:post) do
325+
ParanoidPost.create(title: "test")
326+
end
327+
328+
before do
329+
post.with_session do |session|
330+
session.with_transaction(write_concern: {w: :majority}) do
331+
post.set(title: "test_new")
332+
post.destroy
333+
end
334+
end
335+
end
336+
337+
it "should perform operations correct and commit result" do
338+
expect(post.title).to eq("test_new")
339+
expect(post).to be_destroyed
340+
end
341+
end
321342
end
322343

323344
describe "#destroyed?" do

0 commit comments

Comments
 (0)