When I use test fixtures to populate test data into mysql database I am running into an unexpected behavior. Only columns explicitly defined in the fixture is populated into the database. However, created_on, created_by, updated_on, updated_by fields along with all fields normally populated by observers are NULL. For example, I have a couple fields that have their values calculated via observers. I want to test that these calculations are performed correctly by the observer, so I don''t want to hard code their values in the fixture. Has anyone else run into this issue? If so, how did you perform testing of these fields? I realize that I could perform these tests without fixtures by creating and saving the object. Behind the scenes, Active Record populates all the fields in the expected manner. Then I could find the saved record and assert_equal the expected calculations. However this approach seems brittle and I rather use fixtures. It doesn''t seem (from the results) that I am getting that the fixtures functionality uses Active Record to serialize data to mysql. Thanks! Asa --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
When I use test fixtures to populate test data into mysql database I am running into an unexpected behavior. Only columns explicitly defined in the fixture is populated into the database. However, created_on, created_by, updated_on, updated_by fields along with all fields normally populated by observers are NULL. For example, I have a couple fields that have their values calculated via observers. I want to test that these calculations are performed correctly by the observer, so I don''t want to hard code their values in the fixture. Has anyone else run into this issue? If so, how did you perform testing of these fields? I realize that I could perform these tests without fixtures by creating and saving the object. Behind the scenes, Active Record populates all the fields in the expected manner. Then I could find the saved record and assert_equal the expected calculations. However this approach seems brittle and I rather use fixtures. It doesn''t seem (from the results) that I am getting that the fixtures functionality uses Active Record to serialize data to mysql. Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
christopher.eagan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-27 18:23 UTC
Re: Ruby on Rails Fixtures
> Only columns explicitly defined in the fixture is populated into the database.I think this is the expected behavior. This way you can set fields to the exact values you want for testing purposes. If those fields were automatically populated (based off the system time when the tests were run?) then your tests would be slightly different each time they ran and thus potentially brittle.> I realize that I could perform these tests without fixtures by creating and saving the object.I think this is a reasonable approach in this case but I am interested to hear if anyone else has suggestions. Chris Eagan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
christopher.eagan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> >> Only columns explicitly defined in the fixture is populated into the >> database. > > I think this is the expected behavior. This way you can set fields to > the exact values you want for testing purposes. If those fields were > automatically populated (based off the system time when the tests were > run?) then your tests would be slightly different each time they ran > and thus potentially brittle. >Correct. I use the following format in my fixtures to set these fields to times relative to when the test is run. created_on: <%= 2.days.ago.strftime("%Y-%m-%d %H:%M:%S") %> --~--~---------~--~----~------------~-------~--~----~ 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 Dec 27, 2006, at 10:50 AM, Jon Garvin wrote:> > christopher.eagan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> >>> Only columns explicitly defined in the fixture is populated into the >>> database. >> >> I think this is the expected behavior. This way you can set >> fields to >> the exact values you want for testing purposes. If those fields were >> automatically populated (based off the system time when the tests >> were >> run?) then your tests would be slightly different each time they ran >> and thus potentially brittle. >> > Correct. I use the following format in my fixtures to set these > fields > to times relative to when the test is run. > > created_on: <%= 2.days.ago.strftime("%Y-%m-%d %H:%M:%S") %> >You could also do this... created_on: <%= 2.days.ago.to_formatted_s(:db) %> -- Building an e-commerce site with Rails? http://www.agilewebdevelopment.com/rails-ecommerce --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > created_on: <%= 2.days.ago.strftime("%Y-%m-%d %H:%M:%S") %> > created_on: <%= 2.days.ago.to_formatted_s(:db) %>this one is shorter/simpler : created_at: <%= 2.days.ago.to_s :db %> Alain --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---