By the way, the main hint was seeing some warnings about constant 
redefinition (DB). Of course, if I had seen your previous message it would 
have helped too :)

Em quinta-feira, 9 de janeiro de 2014 15h42min35s UTC-2, Rodrigo Rosenfeld 
Rosas escreveu:
>
> Em quinta-feira, 9 de janeiro de 2014 14h12min08s UTC-2, Jeremy Evans 
> escreveu:
>>
>> On Thursday, January 9, 2014 6:37:01 AM UTC-8, Rodrigo Rosenfeld Rosas 
>> wrote:
>>>
>>> I'm struggling with an issue with one of my tests which not require the 
>>> full Rails environment... 
>>>
>>> When looking at the full statements log, I can only see a single BEGIN 
>>> line and no COMMIT statement, only a ROLLBACK in the end. And there are 
>>> no INSERT statements outside the BEGIN-ROLLBACK block. But after running 
>>> a single test I can see that the database is no longer empty and I have 
>>> to recreate it... 
>>>
>>> If I replace spec_db_only_helper with spec_helper, which loads the full 
>>> Rails environment, it works for some reason. I can't understand this. 
>>>
>>> Another difference is that I get several SELECT NULL; statements when 
>>> using spec_db_only_helper while they don't show up with spec_helper.rb. 
>>>
>>> There's a single connection in the pool for the test environment. 
>>>
>>> Also, I had to call save_changes with transaction: false in my 
>>> factory-girl Model.save! implementation otherwise it would generate some 
>>> BEGIN-COMMIT blocks inside a DB.transaction(savepoint: true, rollback: 
>>> :always){} block. 
>>>
>>> Any ideas what could be happening here? 
>>>
>>
>> My guess would be problems with your environment.  If BEGIN-COMMIT are 
>> being issued inside a DB.transaction block, and you don't have sharding 
>> enabled and aren't using threads, my only guess is that the model's 
>> database doesn't match DB.  The SELECT NULL statements only showing up with 
>> spec_db_only_helper and not with spec_helper also indicates that two 
>> different Database objects may be in play.  Is Sequel::DATABASES the same 
>> when using both helpers?
>>
>> Thanks,
>> Jeremy
>>
>
> Sorry, I missed your answer. I sent the e-mail from Thunderbird and found 
> out it doesn't automatically mark the message to be followed by me so I 
> didn't get the e-mail and just noticed it by chance when I visited this 
> topic in the browser to answer my own questions.
>
> I'm not sure what was happening, but I know how to fix it. I was using 
> "require 'myapp/db'" in some places and "require_dependency 'myapp/db'" in 
> other places, which were causing the file to be load more than once, 
> extending Sequel multiple times (DB.extension(:connection_validator), for 
> instance).
>
> This was the cause for several "SELECT NULL" I was seeing, I guess... But 
> it also fixed all other problems. But I still don't understand why the 
> records were remaining when looking at the statements in the log.
>
> My guess is that Sequel was recreating the connection multiple times, and 
> some of those connections were not inside the main transaction (which has 
> been canceled by the first closed connection).
>
> I just find it weird that I didn't get any warnings or errors. I'd expect 
> ROLLBACK to raise an error if there was no previous BEGIN, but it seems 
> it's not the case with PG, so I didn't get any errors. Tried: "DB << 
> 'ROLLBACK'". In psql I just get a warning...
>
> That would explain why the records are kept...
>
> I'm only not sure why the connection would be recreated several times, but 
> anyway, I shouln't be extending Sequel multiple times either :P
>
> Sorry for the distraction.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to