I assume there''s now something I''m totally missing here. I''m creating stuff in examples, just plain Foo.create, and the results aren''t getting rolled back. I''m keep getting the following kind of pattern in my logs ... log from example starts here ... SQL (0.0ms) BEGIN SQL (0.0ms) BEGIN ClassFoo Create (0.2ms) INSERT ... Group Load (0.4ms) SELECT ... Contains Create (0.2ms) INSERT ... ... other stuff from example, no transaction stuff ... SQL (1.9ms) COMMIT SQL (0.1ms) ROLLBACK ... log from example ends here ... all examples of the following form produce it describe ClassFoo do ... it "plim-ploms" do foo = ClassFoo.create ... end ... end I''m just wondering if this is caused by those nested transactions. MySQL (which I happen to use) doesn''t support nested transactions and is documented to just silently commit open transaction on new BEGIN. Taken that I''d expect last ROLLBACK not to have any effect. Where do those transactions come from? I''d guess outer transaction to be from RSpec and inner from ActiveRecord (oh, I''m on Rails). And of course, what can I do about this... A bit more stuff in pastie http://pastie.org/354521 -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
On Wed, Jan 7, 2009 at 9:11 AM, Tero Tilus <tero at tilus.net> wrote:> > I''m creating stuff in examples, just plain Foo.create, and the results > aren''t getting rolled back. I''m keep getting the following kind of > pattern in my logsYou probably thought about this already, but did you check the setting of config.use_transactional_fixtures in config.spec_helper.rb? -- Have Fun, Steve Eley (sfeley at gmail.com) ESCAPE POD - The Science Fiction Podcast Magazine http://www.escapepod.org
2009-01-07 13:04, Stephen Eley:> config.use_transactional_fixtures in config.spec_helper.rb?Tried true, false and commenting out. I could not see any difference. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
On Wed, Jan 7, 2009 at 8:11 AM, Tero Tilus <tero at tilus.net> wrote:> I assume there''s now something I''m totally missing here. > > I''m creating stuff in examples, just plain Foo.create, and the results > aren''t getting rolled back. I''m keep getting the following kind of > pattern in my logs > > ... log from example starts here ... > SQL (0.0ms) BEGIN > SQL (0.0ms) BEGIN > ClassFoo Create (0.2ms) INSERT ... > Group Load (0.4ms) SELECT ... > Contains Create (0.2ms) INSERT ... > ... other stuff from example, no transaction stuff ... > SQL (1.9ms) COMMIT > SQL (0.1ms) ROLLBACK > ... log from example ends here ... > > all examples of the following form produce it > > describe ClassFoo do > ... > it "plim-ploms" do > foo = ClassFoo.create > ... > end > ... > end > > I''m just wondering if this is caused by those nested transactions. > MySQL (which I happen to use) doesn''t support nested transactions and > is documented to just silently commit open transaction on new BEGIN. > Taken that I''d expect last ROLLBACK not to have any effect. > > Where do those transactions come from? I''d guess outer transaction > to be from RSpec and inner from ActiveRecord (oh, I''m on Rails).Is the app code opening transactions?> > And of course, what can I do about this... > > A bit more stuff in pastie http://pastie.org/354521 > > -- > Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
2009-01-07 13:08, David Chelimsky:> Is the app code opening transactions?Yes, but only one spot (iirc) which is not anywhere near the model whose test is failing here. I''ll verify tomorrow that the failing test really doesn''t run the app code in question. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
Forgot to mention before. I''m on Rails 2.2.2 and RSpec 1.1.4. Inspired by older discussion touching this issue (see http://www.nabble.com/Database-clearing-td19572270.html) I''ve now got Spec::Runner.configure do |config| config.use_transactional_fixtures = false ... tables_to_truncate = ActiveRecord::Base.connection.tables - ["schema_migrations"] config.before(:all) do tables_to_truncate.each do |table_name| ActiveRecord::Base.connection.execute("TRUNCATE TABLE #{table_name};") end end ... end And if I run rake spec all specs pass. But if I run script/spec spec/models/class_foo_spec.rb then it "finds no ghost foos" do ClassFoo.should have(:no).records end fails. That is the first example of describe ClassFoo. Looks like script/spec runs examples (see pastie http://pastie.org/354521) in the order they are defined and rake spec in reverse order. And that of course makes ClassFoo.should have(:no).records fail when run _after_ examples that create ClassFoo instances (befause ive got transactions off and the db state "bleeds" within one describe. 2009-01-07 16:11, Tero Tilus:> I''m keep getting the following kind of pattern in my logs > > ... log from example starts here ... > SQL (0.0ms) BEGIN > SQL (0.0ms) BEGIN > ClassFoo Create (0.2ms) INSERT ... > Group Load (0.4ms) SELECT ... > Contains Create (0.2ms) INSERT ... > ... other stuff from example, no transaction stuff ... > SQL (1.9ms) COMMIT > SQL (0.1ms) ROLLBACK > ... log from example ends here ...If I turn use_transactional_fixtures off, the outer transaction is gone. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
2009-01-07 23:23, Tero Tilus:> 2009-01-07 13:08, David Chelimsky: > > Is the app code opening transactions? > > Yes, but only one spot (iirc) which is not anywhere near the model > whose test is failing here. I''ll verify tomorrow that the failing > test really doesn''t run the app code in question.Verified, and it didn''t. Transactions I see on the log when running the spec in question come from ActiveRecord (and RSpec if I have use_transactional_fixtures = true). -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
On Thu, Jan 8, 2009 at 3:56 AM, Tero Tilus <tero at tilus.net> wrote:> Forgot to mention before. I''m on Rails 2.2.2 and RSpec 1.1.4.Aha! There''s the problem. RSpec-1.1.4 was released in May and Rails 2.2.2 was released AFTER in November. I''d grab the 1.1.12 release candidates from github: gem sources -a http://gems.github.com [sudo] gem install dchelimsky-rspec [sudo] gem install dchelimsky-rspec-rails Cheers, David> > Inspired by older discussion touching this issue (see > http://www.nabble.com/Database-clearing-td19572270.html) I''ve now got > > Spec::Runner.configure do |config| > config.use_transactional_fixtures = false > ... > tables_to_truncate > ActiveRecord::Base.connection.tables - ["schema_migrations"] > config.before(:all) do > tables_to_truncate.each do |table_name| > ActiveRecord::Base.connection.execute("TRUNCATE TABLE > #{table_name};") > end > end > ... > end > > And if I run rake spec all specs pass. But if I run script/spec > spec/models/class_foo_spec.rb then > > it "finds no ghost foos" do > ClassFoo.should have(:no).records > end > > fails. That is the first example of describe ClassFoo. Looks like > script/spec runs examples (see pastie http://pastie.org/354521) in the > order they are defined and rake spec in reverse order. And that of > course makes ClassFoo.should have(:no).records fail when run _after_ > examples that create ClassFoo instances (befause ive got transactions > off and the db state "bleeds" within one describe. > > 2009-01-07 16:11, Tero Tilus: >> I''m keep getting the following kind of pattern in my logs >> >> ... log from example starts here ... >> SQL (0.0ms) BEGIN >> SQL (0.0ms) BEGIN >> ClassFoo Create (0.2ms) INSERT ... >> Group Load (0.4ms) SELECT ... >> Contains Create (0.2ms) INSERT ... >> ... other stuff from example, no transaction stuff ... >> SQL (1.9ms) COMMIT >> SQL (0.1ms) ROLLBACK >> ... log from example ends here ... > > If I turn use_transactional_fixtures off, the outer transaction is > gone. > > -- > Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
2009-01-08 07:37, David Chelimsky:> I''d grab the 1.1.12 release candidates from github: > > gem sources -a http://gems.github.com > [sudo] gem install dchelimsky-rspec > [sudo] gem install dchelimsky-rspec-railsIt gives me 1.1.11.6. Is that a "1.1.12 release candidate"? Could I git clone 1.1.12 somewhere? I''d love to do that. -- Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/
On Fri, Jan 9, 2009 at 6:37 AM, Tero Tilus <tero at tilus.net> wrote:> 2009-01-08 07:37, David Chelimsky: >> I''d grab the 1.1.12 release candidates from github: >> >> gem sources -a http://gems.github.com >> [sudo] gem install dchelimsky-rspec >> [sudo] gem install dchelimsky-rspec-rails > > It gives me 1.1.11.6. Is that a "1.1.12 release candidate"? > Could I git clone 1.1.12 somewhere? I''d love to do that.Sure. Take a look at http://github.com/dchelimsky/rspec/wikis> > -- > Tero Tilus ## 050 3635 235 ## http://tero.tilus.net/ > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >