hi guys, I needed help in Unit test. i just try to save new data intomy test database. but save method does not works for me. the result shows here def test_new_avail avail = Avail.new(:vendor_id => 1, :last_mod_by => ''Murali'', :updated_at => ''2006-08-17 13:14:59) assert avail.valid? assert avail.save end <false> is not true for both assert. it causes failures not errors while testing. Plz tell me how to save data from my test class. i need to save data from this method not from my fixture. advance Thx regards, Narayana. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Narayana Karthick wrote:> hi guys, > > I needed help in Unit test. i just try to save new data intomy test > database. > but save method does not works for me. the result shows here > > def test_new_avail > avail = Avail.new(:vendor_id => 1, > :last_mod_by => ''Murali'', > :updated_at => ''2006-08-17 13:14:59) > assert avail.valid? > assert avail.save > end > > > <false> is not true > for both assert. > > it causes failures not errors while testing. > > Plz tell me how to save data from my test class. i need to save data > from this method not from my fixture. > >> advance Thx > > regards, > Narayana.If your Avail model has an association with a Vendor model then you can''t associate them by setting avail.vendor_id = 1. You need to do it the same way you would in regular Rails code. def test_new_avail avail = Avail.new(:last_mod_by => ''Murali'', :updated_at => ''2006-08-17 13:14:59) avail.vendor = Vendor.find_by_id(1) assert avail.valid? assert avail.save end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jonathan Telfer wrote:> > If your Avail model has an association with a Vendor model then you > can''t associate them by setting avail.vendor_id = 1. You need to do it > the same way you would in regular Rails code. > > def test_new_avail > avail = Avail.new(:last_mod_by => ''Murali'', > :updated_at => ''2006-08-17 13:14:59) > > avail.vendor = Vendor.find_by_id(1) > > assert avail.valid? > assert avail.save > endI forgot to mention, you''ll need to make sure you load your vendor object into the database using a fixture first. That call to find_by_id could probably use some asserting as well. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi!> assert avail.valid? >one trick I find convenient to get more accurate information in that case is to do something like: assert avail.valid?, "The model is invalid: #{avail.errors.full_messages}" hth Thibaut --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > one trick I find convenient to get more accurate information in that case > is to do something like: > > assert avail.valid?, "The model is invalid: #{avail.errors.full_messages}"Unless you use : assert_valid :) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thibaut Barrère wrote:>> >> one trick I find convenient to get more accurate information in that case >> is to do something like: >> >> assert avail.valid?, "The model is invalid: #{avail.errors.full_messages}" > > > Unless you use : assert_valid :)hi, Thx for Both Guys. now assert avail.valid? assert avail.save NO Errors & No Failures. It passes the both the test, now the problem is, it does not save data into the test database. From fixtures to database, transaction takes place successfully. but for save method the transaction does not take place. Plz help me to solve this problem. advance Thx regards, Narayana. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Narayana Karthick wrote:> Thibaut Barrère wrote: > >> > >> one trick I find convenient to get more accurate information in that case > >> is to do something like: > >> > >> assert avail.valid?, "The model is invalid: #{avail.errors.full_messages}" > > > > > > Unless you use : assert_valid :) > hi, > Thx for Both Guys. > now > assert avail.valid? > assert avail.save > NO Errors & No Failures. > > It passes the both the test, now the problem is, it does not save data > into the test database. From fixtures to database, transaction takes > place successfully. > but for save method the transaction does not take place. > > Plz help me to solve this problem. > > advance Thx > > regards, > Narayana. > > -- > Posted via http://www.ruby-forum.com/.A normal test cycle runs like this.. setup 1. clear the DB 2. load the data from fixtures into the DB run tests 3. start a transaction 4. run the test 5. rollback the transaction 6. lather, rinse, repeat (from 3) So if you save data to the DB from one test, you won''t see any trace of it in the DB when you are done. If you so desire, you can load all of your fixtures into your test db by using rake db:fixtures:load _Kevin --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
snhorne-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Sep-29 14:13 UTC
Re: help needed in UNIT Testing
Jonathan, Why can''t you manually set vendor_id? I''ve done it several times when I wanted to avoid loading the associated record. The only problem I can see is where you need to create the record and immediately use the association.... No problems yet - but I want to make sure I''m not shooting myself in the foot. Starr --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---