# Isolator

> Isolator helps detect non-database side effects during database transactions.

- URL: https://evilmartians.com/opensource/isolator
- GitHub: https://github.com/palkan/isolator
- Authors: Vladimir Dementyev

---

Isolator helps detect non-database side effects during database transactions. Isolator is supposed to be used in tests and on staging.

Examples:

```ruby
# HTTP calls within transaction
User.transaction do
  user = User.new(user_params)
  user.save!
  # HTTP API call
  PaymentsService.charge!(user)
end

#=> raises Isolator::HTTPError

# background job
User.transaction do
  user.update!(confirmed_at: Time.now)
  UserMailer.successful_confirmation(user).deliver_later
end

#=> raises Isolator::BackgroundJobError
```

Of course, Isolator can detect _implicit_ transactions too. Consider this pretty common bad practice—enqueueing background job from `after_create` callback:

```ruby
class Comment < ApplicationRecord
  # the good way is to use after_create_commit
  # (or not use callbacks at all)
  after_create :notify_author

  private

  def notify_author
    CommentMailer.comment_created(self).deliver_later
  end
end

Comment.create(text: "Mars is watching you!")
#=> raises Isolator::BackgroundJobError
```

Isolator is supposed to be used in tests and on staging.
