Skip to content

Commit

Permalink
[DEVX-2655] Fix in_transaction collisions with other gems (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
catks authored Jan 19, 2024
1 parent 6fde6c0 commit df1ed6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/granite/action/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ def run_callbacks(event)

private

attr_accessor :in_transaction
attr_accessor :granite_in_transaction

def transaction(&block)
if in_transaction
if granite_in_transaction
yield
else
run_in_transaction(&block)
end
end

def run_in_transaction
self.in_transaction = true
self.granite_in_transaction = true

TransactionManager.transaction do
TransactionManager.after_commit(self)
yield
end
ensure
self.in_transaction = false
self.granite_in_transaction = false
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/granite/action/transaction_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
end

def execute_perform!(*)
# Simulates the after_commit_everywhere in_transaction helper (https://github.com/Envek/after_commit_everywhere/pull/23)
# to avoid name collisions
in_transaction { 'test' }
end

def in_transaction
yield
end
end
end
Expand Down

0 comments on commit df1ed6d

Please sign in to comment.