database_cleaner-sequel icon indicating copy to clipboard operation
database_cleaner-sequel copied to clipboard

Transaction strategy fails with Sequel

Open brauliobo opened this issue 8 years ago • 5 comments

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

brauliobo avatar Feb 13 '17 13:02 brauliobo

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

kaikuchn avatar Jun 25 '18 09:06 kaikuchn

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

jeffvincent avatar Apr 09 '20 17:04 jeffvincent

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

botandrose avatar Apr 09 '20 22:04 botandrose

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.

jeffvincent avatar Apr 10 '20 15:04 jeffvincent

@jeffvincent Yes, please do!

botandrose avatar Apr 10 '20 15:04 botandrose