Multiple Sequel Databases without a database.yml

376 views
Skip to first unread message

Terry Dellino

unread,
Jul 14, 2012, 4:47:41 PM7/14/12
to database...@googlegroups.com
Hi,
I am testing a Sinatra app which connects to multiple database, with Sequel as the ORM.
How do I supply the database connections to DatabaseCleaner?

I have the following, 
ADB = Sequel.connect("postgres://localhost/analysis_test")
RDB = Sequel.connect("postgres://localhost/realtime_test")

RSpec.configure do |config|
  config.before(:suite) do
    DatabaseCleaner[:sequel,{:connection => <THE DB THAT I WANT>}].strategy = :truncation
    DatabaseCleaner[:sequel,{:connection => <THE DB THAT I WANT>}].clean_with(:truncation)
    # DatabaseCleaner takes :connection as a symbol to a db config in database.yml
    # I do not have a database.yml, so how to I pass the different connections to it?
    # just passing the connection like so DatabaseCleaner[:sequel,{:connection => ABD}]
  end

  config.before(:each) do
    DatabaseCleaner[:sequel,{:connection => <THE DB THAT I WANT>}].start
  end

  config.after(:each) do
    DatabaseCleaner[:sequel,{:connection => <THE DB THAT I WANT>}].clean
  end
end

Ben Mabey

unread,
Jul 14, 2012, 5:49:01 PM7/14/12
to database...@googlegroups.com
Hi Terry,
FYI, I don't know Sequel at all so all of the Sequel support has been
contributed. That said, after looking at the code it looks like you can
pass in the actual Sequel:Database object and it should work. So
something like:

DatabaseCleaner[:sequel,{:connection => Sequel::DATBASES[0]}].strategy =
:truncation
DatabaseCleaner[:sequel,{:connection => Sequel::DATBASES[1]}].strategy =
:transaction

Try that out and let me know how it goes.

A little background on the implementation in case you run into issues
and need to patch it...
When you specify a `:connection` in your config setting that will be set
as the @db in the strategy. For the Sequel adapter this is how it is
being used:

https://github.com/bmabey/database_cleaner/blob/master/lib/database_cleaner/sequel/base.rb#L15-19

-Ben

Terry Dellino

unread,
Jul 14, 2012, 6:53:58 PM7/14/12
to database...@googlegroups.com
It doesn't seem to work :(
Reply all
Reply to author
Forward
0 new messages