<div>
Hi Jono,
</div><div><br></div><div>Is your Retailer created by the spec? I think the tests are run in a transaction that gets rolled back, so only the db session that created the object will be able to see it, this would explain why you can't see it anywhere else.</div>
<div><div><br></div><div>-- </div><div>Richard Taylor<br></div><div><br></div></div>
<p style="color: #A0A0A8;">On Monday, 23 January 2012 at 15:45, Jonathan wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div><div>Hi there,</div><div><br></div><div>Long time lurker, first time caller. I've come across a strange</div><div>problem in my rails tests and I've seen a lot of good advice come from</div><div>this list.</div><div><br></div><div>I'm dealing with an old app (using rails 2.3 and postgres), written</div><div>years ago by people unknown and I've decided to get rid of the old</div><div>fixtures and replace them with factories and transactional specs.</div><div><br></div><div>I have a spec where a model is created (Retailer), it's an acceptance</div><div>spec and it calls out to an instance of the app running in test mode</div><div>to see if the retailer exists. It turns out that it doesn't. But it</div><div>should.</div><div><br></div><div>Some debugging has revealed that the model is accessible in the spec,</div><div>but nowhere else (not in the instance of the app or even the postgres</div><div>command line).</div><div><br></div><div>I've been printing debug information and looking through logs for a</div><div>while now, this is the latest thing I've done which indicates to me</div><div>that I have no idea what's wrong:</div><div><br></div><div>In the spec:</div><div><br></div><div> puts "retailers: #{Retailer.count}"</div><div> puts "waiting..."</div><div> sleep(60)</div><div> puts "retailers: #{Retailer.count}"</div><div><br></div><div>The results are:</div><div><br></div><div>retailers: 1</div><div>waiting...</div><div>retailers: 1</div><div><br></div><div>During the sleep(60) I go to the psql command line and type this:</div><div><br></div><div>select count(*) from retailer;</div><blockquote type="cite"><div>0</div></blockquote><div><br></div><div>I've changed the postgres logs to print out debug information and I get this:</div><div><br></div><div>(2012-01-23 15:21:00 GMT, database: pi_test, user: testuser) LOG:</div><div>statement: SELECT count(*) AS count_all FROM "retailer"</div><div>(2012-01-23 15:21:04 GMT, database: pi_test, user: testuser) LOG:</div><div>statement: select count(*) from retailer;</div><div>(2012-01-23 15:22:00 GMT, database: pi_test, user: testuser) LOG:</div><div>statement: SELECT count(*) AS count_all FROM "retailer"</div><div><br></div><div>The first and last lines are coming from rails, the middle line is my</div><div>command line statement.</div><div><br></div><div>Does anyone have any idea where to look next? They're accessing the</div><div>same database, with the same user, executing (pretty much) the same</div><div>thing, and they're getting different results!</div><div><br></div><div>Thanks,</div><div>Jono</div><div>_______________________________________________</div><div>Chat mailing list</div><div><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a></div><div><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a></div></div></div></span>
</blockquote>
<div>
<br>
</div>