Skip to content

Add cleaning_with method #425

@datibbaw

Description

@datibbaw

Hi,

I'm slowly transitioning my tests to use transaction based cleaning instead of truncation. To do this, I'm currently using an around method which will use the strategy I want only for that test;

around(:each) { |example| DatabaseCleaner.cleaning_with(:transaction, &example) }

This is my extension:

module DatabaseCleaner
  class Base
    def cleaning_with(*args, &block)
      create_strategy(*args).cleaning(&block)
    end
  end

  class << self
    def cleaning_with(*args, &inner_block)
      connections.reduce(inner_block) do |curr_block, connection|
        proc { connection.cleaning_with(*args, &curr_block) }
      end.call
    end
  end
end

Would you consider adding this to the project itself? Btw, I realise doing this introduces some code repetition, I haven't yet looked at that because I didn't want to touch the original source code yet ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions