Question

I am writing proof of concept tests using an existing Cucumber and Ruby suite. The corporation I am doing this for has a stack that includes Java and DB2 among other things.

Currently the tests that use the database degrade our test database, and for many reasons I can't wipe the database away and replace it with an imaged version.

I am interested in the idea of using a transaction strategy to clean the database, and I am considering the database_cleaner gem.

It seems as if database_cleaner needs an ORM to work with. I do not have access to the schema at this point, and ActiveRecord can't access what it needs with my credentials.

Two questions:

  1. Do ORMs always need access to the schema?
  2. Do you always need an ORM to clean a database using the transaction strategy?

Also a bonus if anybody knows gems that are available that work with ruby 1.8.7 (no jRuby yet), windows, DB2, etc.

Was it helpful?

Solution

  1. Do ORMs always need access to the schema?

Schema? As in a text dump of the database's tables and relational fields and indexes? No. Do they need to be able to read the database's house-keeping data that describes the tables and their relationships? Yes. That's how they build models.

  1. Do you always need an ORM to clean a database using the transaction strategy?

Heck no. You can go all old-school on it and write it in the SQL for that particular DBM, assuming it supports transactions. An ORM just makes it more portable and usually a lot easier to write because you're relying on it to know how to generate the appropriate SQL.

I like Sequel for my ORM because I can use raw SQL if I insist otherwise I can use it with "datasets" or with full models and relational information about them. Plus, it generates very nice SQL, which I can easily check. I highly recommend it.

Active Record comes with Rails and is probably the most used ORM with Ruby as a result. That doesn't mean it's the best, which is a matter of opinion, but it is common. Active Record isn't isolated to Rails use; You can use it with regular Ruby apps too, though that's a little bit like going against the flow. I used it in the past to tie Ruby to a legacy database, without the Rails layer, and it worked fine.

I haven't used DataMapper in a while, but it seemed nice when I was using it, and I'd recommend looking at it. Everyone's brain assimilates data differently and we like different APIs, hence variety in our ORMs, so it might flow into your brain where the others don't go willingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top