DatabaseCleaner / database_cleaner-sequel

MIT License
17 stars 11 forks source link

Transaction strategy fails with Sequel #2

Open brauliobo opened 7 years ago

brauliobo commented 7 years ago

Backtrace:

NoMethodError: undefined method `pop' for nil:NilClass
  /home/braulio/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/database_cleaner-1.5.3/lib/database_cleaner/sequel/transaction.rb:31:in `clean'
  /home/braulio/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/database_cleaner-1.5.3/lib/database_cleaner/base.rb:46:in `clean_with'
  /home/braulio/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `block in clean_with'
  /home/braulio/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `each'
  /home/braulio/.rbenv/versions/2.2.4/lib/ruby/gems/2.2.0/gems/database_cleaner-1.5.3/lib/database_cleaner/configuration.rb:91:in `clean_with'
  /home/braulio/Projects/olery/scheduler/spec/support/database_cleaner.rb:7:in `block (2 levels) in <top (required)>'

Multiple threads being used

kaikuchn commented 6 years ago

I just ran into the same problem. In my case it's because Sequel::DATABASES was empty when calling DatabaseCleaner.start.

Thus I simply had to initialise the connection to my database before calling DatabaseCleaner.start

jeffvincent commented 4 years ago

Ran into this as well. Updated implementation and it is working as expected:

class Minitest::Spec
  before :each do
    DatabaseCleaner[:sequel].start
  end

  after :each do
    DatabaseCleaner[:sequel].clean
  end
end
botandrose commented 4 years ago

@jeffvincent It sounds like maybe this situation could be addressed in the README? What do you think?

jeffvincent commented 4 years ago

Totally agree! tbh, I wasn't confident enough in my solution. Was expecting to hear about all kinds of terrible externalities I caused by doing things this way :)

An update to the README would certainly help future-me. I'm happy to create PR, if you think that's a good idea.

botandrose commented 4 years ago

@jeffvincent Yes, please do!