Forum: Ruby on Rails Unit tests leave data behind when they should not

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5b336f18b089138ec0968b2d9f12f03b?d=identicon&s=25 Sergei Serdyuk (sserdyuk)
on 2006-03-20 02:40
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
24d3102d656a4654db23d28382a2d6f0?d=identicon&s=25 Timothy Bennett (Guest)
on 2006-03-20 03:05
(Received via mailing list)
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
5b336f18b089138ec0968b2d9f12f03b?d=identicon&s=25 Sergei Serdyuk (sserdyuk)
on 2006-03-20 17:27
Thank you Tim.

> Hope that helps,
>
> Tim
8716cce9a7b721786e5425b8cc1f9951?d=identicon&s=25 sean lynch (Guest)
on 2006-03-20 17:39
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
This topic is locked and can not be replied to.