Hi all<br><br>I&#39;m having problems with data in my specs - i&#39;m probably just going about things the wrong way though.<br><br>I&#39;m testing a model (called Property) that uses acts_as_tree, and for now have just done some specs for the basic acts_as_tree functionality - just as a sanity check, i thought, but i&#39;m getting fails.<br>
<br>In a before(:all) block, i&#39;m creating a bunch of objects and saving them to the database - like this:<br><br>describe Property, &quot;with a fresh property tree&quot; do<br>&nbsp; before(:all) do<br>&nbsp;&nbsp;&nbsp; @root = Property.new(:name =&gt; &quot;Root&quot;)<br>
&nbsp;&nbsp;&nbsp; @<a href="http://root.id">root.id</a> = 0 #root.id must be 0 for acts as tree to work properly<br>&nbsp;&nbsp;&nbsp; @root.save<br>&nbsp;&nbsp;&nbsp; @role = @root.children.create(:name =&gt; &quot;Job Role&quot;)<br>&nbsp;&nbsp;&nbsp; @dept = @root.children.create(:name =&gt; &quot;Department&quot;)<br>
&nbsp;&nbsp;&nbsp; ...etc<br>&nbsp; end<br><br>&nbsp; describe &quot;,standard acts_as_tree methods,&quot; do<br>&nbsp; <br>&nbsp;&nbsp;&nbsp; #this test is failing<br>&nbsp;&nbsp;&nbsp; it &quot;class.root&quot; do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property.root.should eql(@root)<br>&nbsp;&nbsp;&nbsp; end<br>&nbsp; end<br><br>
and the fail report from the above test:<br>&#39;Property with a fresh property tree ,standard acts_as_tree methods, class.root&#39; FAILED<br>expected #&lt;Property id: 0, parent_id: nil, name: &quot;Root&quot;&gt;, got #&lt;Property id: 976, parent_id: nil, name: &quot;Root&quot;&gt; (using .eql?)<br>
./spec/models/property_spec.rb:50:<br>script/spec:4:<br><br>&nbsp; <br><br>My problems seem to be arising from the fact that when i run the test, the objects i created last time are still in the database.&nbsp; Shouldn&#39;t they be cleared out automatically?&nbsp; This in turn is preventing me from saving root with an id of 0.&nbsp; If i test all of this stuff in the console it works fine, but it&#39;s failing in my tests, suggesting that my tests are broken.&nbsp; Am i setting up my data in the wrong way?<br>