For testing, I use: self.use_transactional_fixtures = true This should cause a ROLLBACK for each test case. If I run a single file, foo_controller_test.rb, it works as expected. I see BEGIN and ROLLBACK 8 times in the log files. But if I run: rake test:functionals I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb that deals with this is : def teardown_with_fixtures return unless defined?(ActiveRecord::Base) && ! ActiveRecord::Base.configurations.blank? # Rollback changes if a transaction is active. if use_transactional_fixtures? && Thread.current[''open_transactions''] != 0 ActiveRecord::Base.connection.rollback_db_transaction Thread.current[''open_transactions''] = 0 end ActiveRecord::Base.verify_active_connections! end and I found that Thread.current[''open_transactions''] equals zero in these cases. anyone else encounter this or see something I''m missing? I guess I''ll need to try to follow the increment/decrement of open_transactions. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 8 Oct 2007, at 04:26, dailer wrote:> > > For testing, I use: > > self.use_transactional_fixtures = true > > > This should cause a ROLLBACK for each test case. If I run a single > file, foo_controller_test.rb, it works as expected. I see BEGIN and > ROLLBACK 8 times in the log files. But if I run: > > rake test:functionals > > I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb > that deals with this is : >This suggests that some of your code is committing transactions. Fred --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 8, 4:22 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 8 Oct 2007, at 04:26, dailer wrote: > > > > > > > For testing, I use: > > > self.use_transactional_fixtures = true > > > This should cause a ROLLBACK for each test case. If I run a single > > file, foo_controller_test.rb, it works as expected. I see BEGIN and > > ROLLBACK 8 times in the log files. But if I run: > > > rake test:functionals > > > I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb > > that deals with this is : > > This suggests that some of your code is committing transactions. > > Fredyea, I checked for that, and for creating Threads. Nothing. Looking at the stacktrace of the call to commit, it appears active scaffold might have something to do with this. It''s got it''s own transaction wrapped around this. But it still seems like Thread.current[''open_transactions''] should be 1 instead of zero in fixtures teardown. And certainly the result of running this via "rake test:functionals" should match the result running the file individually. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 8, 8:39 am, dailer <d.sai...-Wuw85uim5zDR7s880joybQ@public.gmane.org> wrote:> On Oct 8, 4:22 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On 8 Oct 2007, at 04:26, dailer wrote: > > > > For testing, I use: > > > > self.use_transactional_fixtures = true > > > > This should cause a ROLLBACK for each test case. If I run a single > > > file, foo_controller_test.rb, it works as expected. I see BEGIN and > > > ROLLBACK 8 times in the log files. But if I run: > > > > rake test:functionals > > > > I get 3 COMMITs, 196 BEGINS and 193 ROLLBACKs. The code in fixtures.rb > > > that deals with this is : > > > This suggests that some of your code is committing transactions. > > > Fred > > yea, I checked for that, and for creating Threads. Nothing. > > Looking at the stacktrace of the call to commit, it appears active > scaffold might have something to do with this. It''s got it''s own > transaction wrapped around this. But it still seems like > Thread.current[''open_transactions''] should be 1 instead of zero in > fixtures teardown. And certainly the result of running this via "rake > test:functionals" should match the result running the file > individually.This was caused by having 2 controller testers with the same class name (cut/paste bug). Weird. I mean everything worked except the rollback of one test case. So whatever you do, don''t do that. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Reasonably Related Threads
- unit test failing
- Model records are not saved to database in during tests
- Verifying some understanding about manipulating DB data in before/after callbacks in RSpec
- Setting use_transactional_fixtures=false for a single spec - a bad idea?
- in-memory SQLite for testing