[LRUG] Same query, different results
Jonathan
j.fantham at gmail.com
Mon Jan 23 08:00:37 PST 2012
Yeah it is. It's created in a before(:each).
Ok thanks, so I guess can't use transactional specs and I'll need to
stick with fixtures for now. Pity!
Thanks,
Jono.
On 23 January 2012 15:53, Richard Taylor <richard at richt.co.uk> wrote:
> Hi Jono,
>
> 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.
>
> --
> Richard Taylor
>
> On Monday, 23 January 2012 at 15:45, Jonathan wrote:
>
> Hi there,
>
> Long time lurker, first time caller. I've come across a strange
> problem in my rails tests and I've seen a lot of good advice come from
> this list.
>
> I'm dealing with an old app (using rails 2.3 and postgres), written
> years ago by people unknown and I've decided to get rid of the old
> fixtures and replace them with factories and transactional specs.
>
> I have a spec where a model is created (Retailer), it's an acceptance
> spec and it calls out to an instance of the app running in test mode
> to see if the retailer exists. It turns out that it doesn't. But it
> should.
>
> Some debugging has revealed that the model is accessible in the spec,
> but nowhere else (not in the instance of the app or even the postgres
> command line).
>
> I've been printing debug information and looking through logs for a
> while now, this is the latest thing I've done which indicates to me
> that I have no idea what's wrong:
>
> In the spec:
>
> puts "retailers: #{Retailer.count}"
> puts "waiting..."
> sleep(60)
> puts "retailers: #{Retailer.count}"
>
> The results are:
>
> retailers: 1
> waiting...
> retailers: 1
>
> During the sleep(60) I go to the psql command line and type this:
>
> select count(*) from retailer;
>
> 0
>
>
> I've changed the postgres logs to print out debug information and I get
> this:
>
> (2012-01-23 15:21:00 GMT, database: pi_test, user: testuser) LOG:
> statement: SELECT count(*) AS count_all FROM "retailer"
> (2012-01-23 15:21:04 GMT, database: pi_test, user: testuser) LOG:
> statement: select count(*) from retailer;
> (2012-01-23 15:22:00 GMT, database: pi_test, user: testuser) LOG:
> statement: SELECT count(*) AS count_all FROM "retailer"
>
> The first and last lines are coming from rails, the middle line is my
> command line statement.
>
> Does anyone have any idea where to look next? They're accessing the
> same database, with the same user, executing (pretty much) the same
> thing, and they're getting different results!
>
> Thanks,
> Jono
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
>
>
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
More information about the Chat
mailing list