[LRUG] Same query, different results

Jonathan j.fantham at gmail.com
Mon Jan 23 07:45:03 PST 2012


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



More information about the Chat mailing list