<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: First Rails gotcha: Rails doesn&#8217;t tear down fixture data</title>
	<atom:link href="http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/</link>
	<description>Jamie Flournoy's Software Development Blog</description>
	<lastBuildDate>Fri, 19 Mar 2010 02:13:16 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: highatmosray</title>
		<link>http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/comment-page-1/#comment-6734</link>
		<dc:creator>highatmosray</dc:creator>
		<pubDate>Wed, 21 May 2008 14:56:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/#comment-6734</guid>
		<description>Great... but it seems that this does not work completely. However when i put  
&#039;self.use_transactional_fixtures = false&#039; it does.
So somehow everything is in a transaction and therefor cannot be deleted, which makes sense because you cannot delete something that is not there  yet.
The problem i ran into next was the data created in my tests was still in the DB.
My first guess was to perform a rollback and close the transaction like you normally would and then call the delete_all. This worked for me


 def teardown
    ActiveRecord::Base.connection.rollback_db_transaction
    Fixtures.all_loaded_fixtures.each do &#124;table_name, fixtures&#124;
      klass = Module.const_get(table_name.to_s.classify)
      klass.delete_all
    end
  end</description>
		<content:encoded><![CDATA[<p>Great&#8230; but it seems that this does not work completely. However when i put<br />
&#8217;self.use_transactional_fixtures = false&#8217; it does.<br />
So somehow everything is in a transaction and therefor cannot be deleted, which makes sense because you cannot delete something that is not there  yet.<br />
The problem i ran into next was the data created in my tests was still in the DB.<br />
My first guess was to perform a rollback and close the transaction like you normally would and then call the delete_all. This worked for me</p>
<p> def teardown<br />
    ActiveRecord::Base.connection.rollback_db_transaction<br />
    Fixtures.all_loaded_fixtures.each do |table_name, fixtures|<br />
      klass = Module.const_get(table_name.to_s.classify)<br />
      klass.delete_all<br />
    end<br />
  end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jamie Flournoy</title>
		<link>http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/comment-page-1/#comment-2216</link>
		<dc:creator>Jamie Flournoy</dc:creator>
		<pubDate>Wed, 07 Nov 2007 18:19:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/#comment-2216</guid>
		<description>Thanks! I&#039;m currently preloading all fixtures at the start of the test suite and letting Rails roll back the tests&#039; changes each time, but your code is helpful in case someone wants to do the per-test load-then-drop method.

Presumably if there are foreign keys then there would need to be some additional code that made the ordering correct.</description>
		<content:encoded><![CDATA[<p>Thanks! I&#8217;m currently preloading all fixtures at the start of the test suite and letting Rails roll back the tests&#8217; changes each time, but your code is helpful in case someone wants to do the per-test load-then-drop method.</p>
<p>Presumably if there are foreign keys then there would need to be some additional code that made the ordering correct.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kristian Hellquist</title>
		<link>http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/comment-page-1/#comment-2202</link>
		<dc:creator>Kristian Hellquist</dc:creator>
		<pubDate>Wed, 07 Nov 2007 09:23:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.pervasivecode.com/blog/2007/05/23/first-rails-gotcha-rails-doesnt-tear-down-fixture-data/#comment-2202</guid>
		<description>&#039;&#039;&#039;Monkeypatching Rails so that all fixtures that have been loaded are deleted when the test class has finished running&#039;&#039;&#039;



in your test_helper.rb:
&lt;pre&gt;
class Test::Unit::TestCase
  def teardown
    Fixtures.all_loaded_fixtures.each do &#124;table_name, fixtures&#124;      
      klass = Module.const_get(table_name.to_s.classify) 
      klass.delete_all
    end
  end
end
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>&#8221;&#8217;Monkeypatching Rails so that all fixtures that have been loaded are deleted when the test class has finished running&#8221;&#8217;</p>
<p>in your test_helper.rb:</p>
<pre>
class Test::Unit::TestCase
  def teardown
    Fixtures.all_loaded_fixtures.each do |table_name, fixtures|
      klass = Module.const_get(table_name.to_s.classify)
      klass.delete_all
    end
  end
end
</pre>
]]></content:encoded>
	</item>
</channel>
</rss>
