Sergei Serdyuk
2006-Mar-20 01:40 UTC
[Rails] Unit tests leave data behind when they should not
Hi, I was confused yesterday. I have bunch of tests and one of those was testing ActiveRecord::save and it was all right, but next method failed because table still had newly created record. All documentation suggests that it should not be the case and that data is reloaded from fixtures before every method is run. I am running edge rails and really did not have anything special done about unit testing setup. Anybody can suggest where to look for the cause? Sergei -- Posted via http://www.ruby-forum.com/.
Timothy Bennett
2006-Mar-20 02:05 UTC
[Rails] Unit tests leave data behind when they should not
Since 1.0, Rails tries to use transactions during testing, to help with performance. So, if you''re database does not support transactions, the tests won''t work correctly. If you''re using MySQL, you can enable transactions by attaching "engine = innodb" to the end of your create table statements. Alternatively, you can add this line to your test classes: self.use_transactional_fixtures = false Hope that helps, Tim On Mar 19, 2006, at 5:40 PM, Sergei Serdyuk wrote:> Hi, > > I was confused yesterday. I have bunch of tests and one of those was > testing ActiveRecord::save and it was all right, but next method > failed > because table still had newly created record. All documentation > suggests > that it should not be the case and that data is reloaded from fixtures > before every method is run. > I am running edge rails and really did not have anything special done > about unit testing setup. > Anybody can suggest where to look for the cause? > > Sergei > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Sergei Serdyuk
2006-Mar-20 16:28 UTC
[Rails] Re: Unit tests leave data behind when they should not
Thank you Tim.> Hope that helps, > > Tim-- Posted via http://www.ruby-forum.com/.
sean lynch
2006-Mar-20 16:40 UTC
[Rails] Re: Unit tests leave data behind when they should not
In mySQL you can alter an existing table (named table_name) to use InnoDB with the command: mysql> alter table table_name TYPE=InnoDB; just substitute your table name, and run at the mysql prompt (or however you prefer to run stand alone sql. -sean Timothy Bennett wrote:> Since 1.0, Rails tries to use transactions during testing, to help > with performance. So, if you''re database does not support > transactions, the tests won''t work correctly. If you''re using MySQL, > you can enable transactions by attaching "engine = innodb" to the end > of your create table statements. Alternatively, you can add this > line to your test classes: > > self.use_transactional_fixtures = false > > Hope that helps, > > Tim-- Posted via http://www.ruby-forum.com/.