Hi, I want to write a spec to test whether my code is hitting the database or not . In my model spec file I tried different ways to save the database into my to database such as @user.save! or creating new user by User.create . Is there any way to store data in database with rspec code . Thnaks, Nallamani --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nallamani wrote:> I want to write a spec to test whether my code is hitting the database > or not . > > In my model spec file I tried different ways to save the database into > my to database such as @user.save! or creating new user by > User.create . > > Is there any way to store data in database with rspec code .Folks do that all the time. Why don''t you think the data is in the database? Can you read the data back, in the spec, and print it out? Most test rigs run with transactions turned on. Google for [rspec transactions]. They roll back all database changes after each specification. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Yaa I can read the data back . But it is not storing in the database for some reason . Every time I am creating a new user , the can see an incremental user id . But none of the data is getting stored in database . Thanks, Nallamani On Apr 4, 12:14 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nallamani wrote: > > I want to write a spec to test whether my code is hitting the database > > or not . > > > In my model spec file I tried different ways to save the database into > > my to database such as @user.save! or creating new user by > > User.create . > > > Is there any way to store data in database with rspec code . > > Folks do that all the time. > > Why don''t you think the data is in the database? Can you read the data back, in > the spec, and print it out? > > Most test rigs run with transactions turned on. Google for [rspec transactions]. > They roll back all database changes after each specification. > > -- > Phlip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Philip, Here is my code in my spec before (:each) do @user1 = User.new(:login => "testing", :email => "jijiji-/E1597aS9LQAvxtiuMwx3w@public.gmane.org", :password => "hihowru", :password_confirmation => "hihowru") @user1.save! end I can''t see this data getting stored in database On Apr 4, 2:39 pm, Nallamani <padmamadhu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yaa I can read the data back . But it is not storing in the database > for some reason . > > Every time I am creating a new user , the can see an incremental user > id . But none of the data is getting stored in database . > > Thanks, > Nallamani > > On Apr 4, 12:14 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Nallamani wrote: > > > I want to write a spec to test whether my code is hitting the database > > > or not . > > > > In my model spec file I tried different ways to save the database into > > > my to database such as @user.save! or creating new user by > > > User.create . > > > > Is there any way to store data in database with rspec code . > > > Folks do that all the time. > > > Why don''t you think the data is in the database? Can you read the data back, in > > the spec, and print it out? > > > Most test rigs run with transactions turned on. Google for [rspec transactions]. > > They roll back all database changes after each specification. > > > -- > > Phlip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nallamani, when are you checking for the data? Philp''s point about transactions is that all the data is rolled back out of the db after the test. If you''re expecting to look at the table after the testing is done you won''t see anything. On Apr 4, 3:53 pm, Nallamani <padmamadhu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Philip, > > Here is my code in my spec > > before (:each) do > > @user1 = User.new(:login => "testing", :email => > "jij...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org", :password => "hihowru", :password_confirmation => > "hihowru") > @user1.save! > > end > > I can''t see this data getting stored in database > > On Apr 4, 2:39 pm, Nallamani <padmamadhu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yaa I can read the data back . But it is not storing in the database > > for some reason . > > > Every time I am creating a new user , the can see an incremental user > > id . But none of the data is getting stored in database . > > > Thanks, > > Nallamani > > > On Apr 4, 12:14 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Nallamani wrote: > > > > I want to write a spec to test whether my code is hitting the database > > > > or not . > > > > > In my model spec file I tried different ways to save the database into > > > > my to database such as @user.save! or creating new user by > > > > User.create . > > > > > Is there any way to store data in database with rspec code . > > > > Folks do that all the time. > > > > Why don''t you think the data is in the database? Can you read the data back, in > > > the spec, and print it out? > > > > Most test rigs run with transactions turned on. Google for [rspec transactions]. > > > They roll back all database changes after each specification. > > > > -- > > > Phlip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Andy , I wasted two days on Rspec and story runner . Is there any way to delay the roll back . With normal integration testing I can store in database . On Apr 5, 11:39 am, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> Nallamani, when are you checking for the data? Philp''s point about > transactions is that all the data is rolled back out of the db after > the test. If you''re expecting to look at the table after the testing > is done you won''t see anything. > > On Apr 4, 3:53 pm, Nallamani <padmamadhu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Philip, > > > Here is my code in my spec > > > before (:each) do > > > @user1 = User.new(:login => "testing", :email => > > "jij...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org", :password => "hihowru", :password_confirmation => > > "hihowru") > > @user1.save! > > > end > > > I can''t see this data getting stored in database > > > On Apr 4, 2:39 pm, Nallamani <padmamadhu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Yaa I can read the data back . But it is not storing in the database > > > for some reason . > > > > Every time I am creating a new user , the can see an incremental user > > > id . But none of the data is getting stored in database . > > > > Thanks, > > > Nallamani > > > > On Apr 4, 12:14 pm, Phlip <phlip2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Nallamani wrote: > > > > > I want to write a spec to test whether my code is hitting the database > > > > > or not . > > > > > > In my model spec file I tried different ways to save the database into > > > > > my to database such as @user.save! or creating new user by > > > > > User.create . > > > > > > Is there any way to store data in database with rspec code . > > > > > Folks do that all the time. > > > > > Why don''t you think the data is in the database? Can you read the data back, in > > > > the spec, and print it out? > > > > > Most test rigs run with transactions turned on. Google for [rspec transactions]. > > > > They roll back all database changes after each specification. > > > > > -- > > > > Phlip--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nallamani wrote:> I wasted two days on Rspec and story runner .And you will continue to spend quality time with them! > Is there any way to delay the roll back . Almost all testing on databases should roll the database back after each test case. The only general exception I can think of is tests that help build a new database engine. What do you want to do with that data, in the database? If you intend to inspect it, then you should add a .should (or an assertion) to your test case, to inspect that data automatically. Then the transaction will work for you, not against you. If you are putting the data in the database for some non-test purpose, look at migrations. > With normal integration testing I can store in database . Your test_helper.rb may have had use_transactional_fixtures = false. -- Phlip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nallamani, Use rake spec:db:fixtures:load to create data for testing the interface in dev mode or use Migrations to seed data for deployment If your testing model functionality use .should if you are just wanting to test that ActiveRecord works.... DON''T best of luck -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Philip and Pratt for your timely help . I will stick to integration testing for time being and later shift to rspec . On Apr 6, 2:50 am, Keynan Pratt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Nallamani, > > Use rake spec:db:fixtures:load > to create data for testing the interface in dev mode > or use Migrations to seed data for deployment > > If your testing model functionality use .should > if you are just wanting to test that ActiveRecord works.... DON''T > > best of luck > > -- > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---