# Test not rolling back

**URL:** <https://www.ruby-forum.com/t/test-not-rolling-back/116627>\
**Category:** Rails\
**Created:** [October 8, 2007, 5:27am UTC](https://www.ruby-forum.com/t/test-not-rolling-back/116627 "2007-10-08T05:27:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [October 8, 2007, 5:27am UTC](https://www.ruby-forum.com/t/test-not-rolling-back/116627/1 "2007-10-08T05:27:16Z")

</div>

For testing, I use:

self.use\_transactional\_fixtures = true

This should cause a ROLLBACK for each test case. If I run a single  
file, foo\_controller\_test.rb, it works as expected. I see BEGIN and  
ROLLBACK 8 times in the log files. But if I run:

rake test:functionals

I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb  
that deals with this is :

```
  def teardown_with_fixtures
    return unless defined?(ActiveRecord::Base) && !

```

ActiveRecord::Base.configurations.blank?  
# Rollback changes if a transaction is active.  
if use\_transactional\_fixtures? &&  
Thread.current[‘open\_transactions’] != 0  
ActiveRecord::Base.connection.rollback\_db\_transaction  
Thread.current[‘open\_transactions’] = 0  
end  
ActiveRecord::Base.verify\_active\_connections!  
end

and I found that Thread.current[‘open\_transactions’] equals zero in  
these cases.

anyone else encounter this or see something I’m missing? I guess I’ll  
need to try to follow the increment/decrement of open\_transactions.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [October 8, 2007, 10:23am UTC](https://www.ruby-forum.com/t/test-not-rolling-back/116627/2 "2007-10-08T10:23:20Z")

</div>

On 8 Oct 2007, at 04:26, dailer wrote:

> rake test:functionals
> 
> I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb  
> that deals with this is :

This suggests that some of your code is committing transactions.

Fred

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [October 8, 2007, 2:40pm UTC](https://www.ruby-forum.com/t/test-not-rolling-back/116627/3 "2007-10-08T14:40:37Z")

</div>

On Oct 8, 4:22 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > This should cause a ROLLBACK for each test case. If I run a single  
> > Fred  
> > yea, I checked for that, and for creating Threads. Nothing.

Looking at the stacktrace of the call to commit, it appears active  
scaffold might have something to do with this. It’s got it’s own  
transaction wrapped around this. But it still seems like  
Thread.current[‘open\_transactions’] should be 1 instead of zero in  
fixtures teardown. And certainly the result of running this via “rake  
test:functionals” should match the result running the file  
individually.

---

<div class="post-metadata">

**Author:** ![dnstevenson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8dc957/32.png) [@dnstevenson](https://www.ruby-forum.com/u/dnstevenson)\
**Post date:** [October 12, 2007, 11:28pm UTC](https://www.ruby-forum.com/t/test-not-rolling-back/116627/4 "2007-10-12T23:28:23Z")

</div>

On Oct 8, 8:39 am, dailer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> individually.  
> This was caused by having 2 controller testers with the same class  
> name (cut/paste bug). Weird. I mean everything worked except the  
> rollback of one test case. So whatever you do, don’t do that.
