Vikrant Chaudhary
2010-Mar-18 10:08 UTC
Records created while tests are running are not being saved.
In following code - require "test_helper" Class SomeControllerTest < ActionController::TestCase def test_something record = SomeModel.create :name => ''test'' record.save! gets end end Above record is not being saved in the database. I can confirm this by pausing execution by calling gets() and doing a "SELECT * FROM some_models" right into the test database which returns no rows. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Steven Hilton
2010-Mar-18 10:13 UTC
Re: Records created while tests are running are not being saved.
On Thu, Mar 18, 2010 at 6:08 AM, Vikrant Chaudhary <nasa42-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In following code - > > require "test_helper" > Class SomeControllerTest < ActionController::TestCase > > def test_something > record = SomeModel.create :name => ''test'' > record.save! > gets > end > > end > > Above record is not being saved in the database. I can confirm this by > pausing execution by calling gets() and doing a "SELECT * FROM > some_models" right into the test database which returns no rows. > > --Tests are ran inside a transaction and are rolled back after each test. In a separate process (i.e. ./script/dbconsole) you will not see the data create from a test, even if you pause execution. You *should* be able to see the insert (and the roll back) happening in test.log Even though the transaction is rolled back, the sequence on the primary key is still advanced, so you should see that effect in a separate process. - Steven -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Vikrant Chaudhary
2010-Mar-18 10:55 UTC
Re: Records created while tests are running are not being saved.
Thanks. On Mar 18, 3:13 pm, Steven Hilton <mshilt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Mar 18, 2010 at 6:08 AM, Vikrant Chaudhary <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > In following code - > > > require "test_helper" > > Class SomeControllerTest < ActionController::TestCase > > > def test_something > > record = SomeModel.create :name => ''test'' > > record.save! > > gets > > end > > > end > > > Above record is not being saved in the database. I can confirm this by > > pausing execution by calling gets() and doing a "SELECT * FROM > > some_models" right into the test database which returns no rows. > > > -- > > Tests are ran inside a transaction and are rolled back after each > test. In a separate process (i.e. ./script/dbconsole) you will not see > the data create from a test, even if you pause execution. > > You *should* be able to see the insert (and the roll back) happening in test.log > > Even though the transaction is rolled back, the sequence on the > primary key is still advanced, so you should see that effect in a > separate process. > > - Steven-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Mar-18 17:59 UTC
Re: Records created while tests are running are not being saved.
On Mar 18, 10:13 am, Steven Hilton <mshilt...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Mar 18, 2010 at 6:08 AM, Vikrant Chaudhary <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Tests are ran inside a transaction and are rolled back after each > test. In a separate process (i.e. ./script/dbconsole) you will not see > the data create from a test, even if you pause execution.you can see the data during the test if you alter the transaction isolation level to read uncommitted (at least you can with mysql) 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Vikrant Chaudhary
2010-Mar-19 04:22 UTC
Re: Records created while tests are running are not being saved.
Just for records. Line #47 - http://code.google.com/p/kopal/source/browse/test/network/connect_controller_test.rb?r=876e7c80c420e5faca9492bd50ed1dd943cb90ac On Mar 18, 3:08 pm, Vikrant Chaudhary <nas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In following code - > > require "test_helper" > Class SomeControllerTest < ActionController::TestCase > > def test_something > record = SomeModel.create :name => ''test'' > record.save! > gets > end > > end > > Above record is not being saved in the database. I can confirm this by > pausing execution by calling gets() and doing a "SELECT * FROM > some_models" right into the test database which returns no rows.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.