Ruby on Rails Wednesday, February 27, 2013

On 27 February 2013 14:51, Rahul Sharma <rahulsharma.rsh@gmail.com> wrote:
> 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?

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

>
> Thanks,
>
> Rahul
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/1XVGDwBZ0FoJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment