views:

76

answers:

3

I've had to add features to an application that depends on a database from another application. I've been able to set up a connection to this external database and pull data from it. However, I'm not sure how to get my main application to create a test database for this external application.

It would be awesome if there some way to pull in the schema for this database and create it in the same manner that 'rake db:test:prepare' does. Is there any configuration capabilities for RSpec to do this, or will I have to roll my own task?

A: 

Is this a Rails app? If so, the db:test:prepare task and the related tasks will still work, even if you are using RSpec.

Mike H
Forgot to mention that. Yes it is a rails app. I'm not sure of db:test:prepare will work in this situation. How does this task know what databases to create. Can I point it to a DB schema from another application so that it includes that database too?
Chris Rittersdorf
A: 

I am not aware of any simple way to do this. You could have a sql schema prepared and load it in your test database trough a custom rake task

But if it is for testing, it might be a good idea for you to look into Factories For example Factory girl

"factory_girl is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (user, admin_user, and so on), including factory inheritance."

And a screencast

Aurélien Bottazzini
A: 

I ended up just running "rake db:test:prepare" for the external application and update the database configs of the application I'm developing to include the test DB for the external application. I'd like to automate the 'rake db:test:prepare' for the external app, however I don't see myself updating its schema that often.

Chris Rittersdorf