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 cleaning_with method #425

Open
datibbaw opened this issue Feb 8, 2016 · 0 comments
Open

Add cleaning_with method #425

datibbaw opened this issue Feb 8, 2016 · 0 comments

Comments

@datibbaw
Copy link

datibbaw commented Feb 8, 2016

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 ;-)

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

No branches or pull requests

1 participant