Skip to content

Commit

Permalink
Fix #destroy hanging after another action inside a transaction (#74)
Browse files Browse the repository at this point in the history
* Fix #destroy hanging after another action inside a transaction

* Add Rspecs
  • Loading branch information
arturantonnikau authored Mar 21, 2024
1 parent 5f46f41 commit 52b652f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def paranoid_field
# @return [ Object ] Update result.
#
def _paranoia_update(value)
paranoid_collection.find(atomic_selector).update_one(value)
paranoid_collection.find(atomic_selector).update_one(value, session: _session)
end
end
end
21 changes: 21 additions & 0 deletions spec/mongoid/paranoia_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ class ParanoidConfiguredReset
expect(post).not_to be_destroyed
end
end

context "when multiple operations wrapped inside transaction" do

let(:post) do
ParanoidPost.create(title: "test")
end

before do
post.with_session do |session|
session.with_transaction(write_concern: {w: :majority}) do
post.set(title: "test_new")
post.destroy
end
end
end

it "should perform operations correct and commit result" do
expect(post.title).to eq("test_new")
expect(post).to be_destroyed
end
end
end

describe "#destroyed?" do
Expand Down

0 comments on commit 52b652f

Please sign in to comment.