On Fri, Jun 17, 2011 at 10:06 AM, Iain Barnett <[email protected]> wrote:
>
> I've set up a very simple spec just to get started with - set up the db, a
> model, and save a instance of the model. I'm trying out the models with the
> Twitter bot I had running with non-model sequel, but on running rspec I get
> this error message:
>
>
You need a new database connection, because the one you used didn't have the
schema you need but wound up in Sequel::DATABASES. This is a known
deficiency but to preserve compatibility with existing code can't be
changed.
The trick here is to use a database connection in a block to run the
migrations BEFORE calling Sequel.connect for your models, roughly like this:
def create_test_db
# Recreate the database
Sequel.connect('postgres:///') do |other_db|
db_name = URI.parse(ENV["DATABASE_URL"]).path[1..-1]
other_db.run("DROP DATABASE IF EXISTS #{db_name}")
other_db.run("CREATE DATABASE #{db_name}")
end
# Migrate the DB to The Present
Sequel.connect(ENV["DATABASE_URL"]) do |db|
Sequel.extension :migration
Sequel::Migrator.run(db, './migrations')
end
end
--
Peter van Hardenberg
San Francisco, California
"Everything was beautiful, and nothing hurt." -- Kurt Vonnegut
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.