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

Add protection of stubbed methods from being called within a db transaction #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nepalez
Copy link
Owner

@nepalez nepalez commented Sep 21, 2019

Use the within_transaction: false for the protection:

---
- class: GoogleTranslateDiff
- chain: translate
- within_transaction: false
- arguments:
    - Color
    - :from: en
      :to:   de
- actions:
    - return: Farbe

This method will raise an exception if the method is executed in a transaction:

GoogleTranslateDiff.translate "Color", from: "en", to: "de"
# => "Farbe"  

# but not within a transaction
ActiveRecord::Base.transaction do
  GoogleTranslateDiff.translate "Color", from: "en", to: "de"
  # => raise #<Isolator::UnsafeOperationError ...>
end

With a new setting `within_transaction: false` you can prevent
calling a stabbed method within a database transaction.

```yaml
---
- class: Foo
  chain:
    - bar
    - baz
  within_transaction: false
  actions:
    - return: 0
```

If you call the method inside a transaction, the call will raise
an exception `::Isolator::UnsafeOperationError` pointing to
the method `Foo.bar.baz(*)`.

Notice that this setting is argument-specific. You can allow it
to be called inside a transaction with some arguments, and
<explicitly> forbid for some other arguments at the same time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant