ActiveRecord newbie question

Hi Guys,

I have a standalone ruby testing framework without rails testing some
webservices. The project uses ActiveRecord to connect to mysql remote
database through mysql adapter and uses very basic Activerecord features
only like “establish_connection” and inserting values in a table. The
model
doesn’t have the usual “up” and “down” methods as the tables are already
present in the database and are outside our control.

I want to delete the data inserted as part of my tests only after my
test
is finished. I have been googling around this and I believe it is
possible
by ActiveRecord transactions. Is it possible to do this without
migrations?
or if with migrations, what sort of migrations would I need?

Thanks,

Rahul

On 27 February 2013 14:51, Rahul S. [email protected]
wrote:

finished. I have been googling around this and I believe it is possible by
ActiveRecord transactions. Is it possible to do this without migrations? or
if with migrations, what sort of migrations would I need?

Migrations are used for changing the structure of the database so you
should not need to do this (assuming you are just inserting values in
an existing table as you say). If you enclose your work in a
transaction then if you perform a rollback before completing the
transaction then it will be undone.

Of course I am sure you are not performing your tests connected to a
production database. Things can go wrong when trying this sort of
thing, especially if you are learning about concepts such as
transactions and migrations at the same time.

Colin

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs