README.md in isolator-0.8.0 vs README.md in isolator-0.9.0

- old
+ new

@@ -108,11 +108,11 @@ **NOTE:** `uniform_notifier` should be installed separately (i.e., added to Gemfile). ### Transactional tests support - - Rails' baked-in [use_transactional_tests](api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html#class-ActiveRecord::FixtureSet-label-Transactional+Tests) + - Rails' baked-in [use_transactional_tests](https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html#class-ActiveRecord::FixtureSet-label-Transactional+Tests) - [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner) gem. Make sure that you require isolator _after_ database_cleaner. ### Supported ORMs - `ActiveRecord` >= 5.1 (4.2 likely till works, but we do not test against it anymore) @@ -157,20 +157,53 @@ Isolator.adapters.sidekiq.ignore_if { Thread.current[:sidekiq_postpone] } ``` You can add as many _ignores_ as you want, the offense is registered iff all of them return false. + +### Using with sidekiq/testing + +If you require sidekiq/testing in your tests after isolator is required then it will blow away isolator's hooks, so you need to require isolator after requiring sidekiq/testing. + +If you're using Rails and want to use isolator in development and staging, then here is a way to do this. + +```ruby + +# Gemfile +gem "isolator", require: false # so it delays loading till after sidekiq/testing + +# config/initializers/isolator.rb +require "sidekiq/testing" if Rails.env.test? + +unless Rails.env.production? # so we get it in staging too + require "isolator" + Isolator.configure do |config| + config.send_notifications = true # ... + end +end +``` + ### Using with legacy Rails codebases If you already have a huge Rails project it can be tricky to turn Isolator on because you'll immediately get a lot of failed specs. If you want to fix detected issues one by one, you can list all of them in the special files `.isolator_todo.yml` and `.isolator_ignore.yml` in the following way: ``` sidekiq: - app/models/user.rb:20 - app/models/sales/**/*.rb ``` +You can ignore the same files in multiple adapters using YML aliases in the following way: + +``` +http_common: &http_common + - app/models/user.rb:20 + +http: *http_common +webmock: *http_common +``` + All the exceptions raised in the listed lines will be ignored. The `.isolator_todo.yml` file is intended to point to the code that should be fixed later, and `.isolator_ignore.yml` points to the code that for some reasons is not expected to be fixed. (See https://github.com/palkan/isolator/issues/40) ### Using with legacy Ruby codebases @@ -203,12 +236,39 @@ ```ruby Isolator.isolate :active_job, target: ActiveJob::Base, method_name: :enqueue, exception_class: Isolator::BackgroundJobError, - details_message: ->(obj, _args) { + details_message: ->(obj) { "#{obj.class.name}(#{obj.arguments})" } + +Isolator.isolate :promoter, + target: UserPromoter, + method_name: :call, + details_message: ->(obj_, args, kwargs) { + # UserPromoter.call(user, role, by: nil) + user, role = args + by = kwargs[:by] + "#{user.name} promoted to #{role} by #{by&.name || "system"})" + } +``` + +Trying to register the same adapter name twice will raise an error. You can guard for it, or remove old adapters before in order to replace them. + +```ruby +unless Isolator.has_adapter?(:promoter) + Isolator.isolate(:promoter, *rest) +end +``` + +```ruby +# Handle code reloading +class Messager +end + +Isolator.remove_adapter(:messager) +Isolator.isolate(:messager, target: Messager, **rest) ``` You can also add some callbacks to be run before and after the transaction: ```ruby