Hi, I''d like to have the results of a migration file that prepopulates my development database available for testing. So, right now, after the usual rake migration, I can access my prepopulated data via script/ console, but not in my unit tests. I''ve reviewed comments on this subject but the custom rake tasks do not work or attempting a fix with RAILS_ENV=test rake db:migrate as a command does not help either. Any suggestion on how I can get the results of my migration available in the test environment? Thanks, Grar -- 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.
On Apr 10, 2:30 pm, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''d like to have the results of a migration file that prepopulates my > development database available for testing. So, right now, after the > usual rake migration, I can access my prepopulated data via script/ > console, but not in my unit tests. I''ve reviewed comments on this > subject but the custom rake tasks do not work or attempting a fix with > RAILS_ENV=test rake db:migrate as a command does not help either. Any > suggestion on how I can get the results of my migration available in > the test environment? >The test database is filled with the data from your fixture files - running migrations against it accomplish nothing because it is wiped at the start of the test run. Your best bet is probably to write something that will dump yml from your database. You should consider using db/seeds.rb to seed your database - migrations are not intended to fufill that need. Fred> Thanks, > > Grar-- 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.
Hi, I''d like to have the results of a migration file that prepopulates my development database available for testing. So, right now, after the usual rake migration, I can access my prepopulated data via script/ console, but not in my unit tests. I''ve reviewed comments on this subject but the custom rake tasks do not work or attempting a fix with RAILS_ENV=test rake db:migrate as a command does not help either. Any suggestion on how I can get the results of my migration available in the test environment? Thanks, Grar -- 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.
Frederick, Thanks. So, my desire to have pre-populated (whether from seeding or otherwise) databases available in testing is unusual? I would have expected a basic interest in having any and all development data, e.g., zip code data, available for testing purposes, but my takeaway from your response is that testing is typically performed on a limited subset of development/production data that has been supplied from fixtures. Can you please confirm? Thanks, Grar On Apr 10, 9:52 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 10, 2:30 pm, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > > I''d like to have the results of a migration file that prepopulates my > > development database available for testing. So, right now, after the > > usual rake migration, I can access my prepopulated data via script/ > > console, but not in my unit tests. I''ve reviewed comments on this > > subject but the custom rake tasks do not work or attempting a fix with > > RAILS_ENV=test rake db:migrate as a command does not help either. Any > > suggestion on how I can get the results of my migration available in > > the test environment? > > The test database is filled with the data from your fixture files - > running migrations against it accomplish nothing because it is wiped > at the start of the test run. Your best bet is probably to write > something that will dump yml from your database. You should consider > using db/seeds.rb to seed your database - migrations are not intended > to fufill that need. > > Fred > > > Thanks, > > > Grar-- 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.
On Apr 10, 3:17 pm, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Frederick, > > Thanks. So, my desire to have pre-populated (whether from seeding or > otherwise) databases available in testing is unusual? I would have > expected a basic interest in having any and all development data, > e.g., zip code data, available for testing purposes, but my takeaway > from your response is that testing is typically performed on a limited > subset of development/production data that has been supplied from > fixtures. Can you please confirm?Correct (although there''s no constraint I''m aware of on the size of your fixture data). You want test runs to be consistent - having the dataset your tests run against change just because you''ve been messing around in development would be a bad thing. More and more people are actually skipping fixtures and using stuff like factory_girl. Fred> > Thanks, > > Grar > > On Apr 10, 9:52 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Apr 10, 2:30 pm, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > > > I''d like to have the results of a migration file that prepopulates my > > > development database available for testing. So, right now, after the > > > usual rake migration, I can access my prepopulated data via script/ > > > console, but not in my unit tests. I''ve reviewed comments on this > > > subject but the custom rake tasks do not work or attempting a fix with > > > RAILS_ENV=test rake db:migrate as a command does not help either. Any > > > suggestion on how I can get the results of my migration available in > > > the test environment? > > > The test database is filled with the data from your fixture files - > > running migrations against it accomplish nothing because it is wiped > > at the start of the test run. Your best bet is probably to write > > something that will dump yml from your database. You should consider > > using db/seeds.rb to seed your database - migrations are not intended > > to fufill that need. > > > Fred > > > > Thanks, > > > > Grar-- 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.
Grar, My recommendation would be to not pre-populate with a migration. I would create a ruby script for that and have developers run that script to get setup. Then I would run that script in the test/test_helper.rb setup or where ever is appropriate if I wanted that data available in my tests. A more conventional approach would be to create fixtures with the test data. Then you can load those fixtures into your development database with "rake db:fixtures:load". Anthony Crumley http://commonthread.com On Sat, Apr 10, 2010 at 8:59 AM, Grary <grary.stimon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I''d like to have the results of a migration file that prepopulates my > development database available for testing. So, right now, after the > usual rake migration, I can access my prepopulated data via script/ > console, but not in my unit tests. I''ve reviewed comments on this > subject but the custom rake tasks do not work or attempting a fix with > RAILS_ENV=test rake db:migrate as a command does not help either. Any > suggestion on how I can get the results of my migration available in > the test environment? > > Thanks, > > Grar > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Thanks guys. What''s strange to me is the idea that Rails testing is not comprehensive, i.e., there are constants, e.g., zip codes, that you will use in production that you didn''t have access to in testing. While I appreciate that testing is built on cases and not exhaustive, I can think of situations in my developing app where I might like to check for "surprises" and I won''t want contrived cases derived from fixtures or factories. I guess what I''m getting at here is the idea that testing might involve statistical checks, e.g., what is the probability that I get some certain result? If I get many low probability results, maybe something''s wrong with my constants or the way I''m handling them, e.g., zip codes. Anyway, this concern straddles the line between uncertainty about inputs, e.g., app constant data like zip codes, and outputs -- what an app does with them. Thanks for your comments, I consider my question well answered. Grar On Apr 11, 4:46 pm, Anthony Crumley <anthony.crum...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Grar, > > My recommendation would be to not pre-populate with a migration. I would > create a ruby script for that and have developers run that script to get > setup. Then I would run that script in the test/test_helper.rb setup or > where ever is appropriate if I wanted that data available in my tests. > > A more conventional approach would be to create fixtures with the test > data. Then you can load those fixtures into your development database with > "rake db:fixtures:load". > > Anthony Crumleyhttp://commonthread.com > > On Sat, Apr 10, 2010 at 8:59 AM, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > I''d like to have the results of a migration file that prepopulates my > > development database available for testing. So, right now, after the > > usual rake migration, I can access my prepopulated data via script/ > > console, but not in my unit tests. I''ve reviewed comments on this > > subject but the custom rake tasks do not work or attempting a fix with > > RAILS_ENV=test rake db:migrate as a command does not help either. Any > > suggestion on how I can get the results of my migration available in > > the test environment? > > > Thanks, > > > Grar > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > . > > For more options, visit this group at > >http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
You might be interested in the Faker gem that will create data for you in all kinds of formats. On Sun, Apr 11, 2010 at 4:55 PM, Grary <grary.stimon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks guys. > > What''s strange to me is the idea that Rails testing is not > comprehensive, i.e., there are constants, e.g., zip codes, that you > will use in production that you didn''t have access to in testing. > While I appreciate that testing is built on cases and not exhaustive, > I can think of situations in my developing app where I might like to > check for "surprises" and I won''t want contrived cases derived from > fixtures or factories. I guess what I''m getting at here is the idea > that testing might involve statistical checks, e.g., what is the > probability that I get some certain result? If I get many low > probability results, maybe something''s wrong with my constants or the > way I''m handling them, e.g., zip codes. Anyway, this concern straddles > the line between uncertainty about inputs, e.g., app constant data > like zip codes, and outputs -- what an app does with them. > > Thanks for your comments, I consider my question well answered. > > Grar > > On Apr 11, 4:46 pm, Anthony Crumley <anthony.crum...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Grar, > > > > My recommendation would be to not pre-populate with a migration. I would > > create a ruby script for that and have developers run that script to get > > setup. Then I would run that script in the test/test_helper.rb setup or > > where ever is appropriate if I wanted that data available in my tests. > > > > A more conventional approach would be to create fixtures with the test > > data. Then you can load those fixtures into your development database > with > > "rake db:fixtures:load". > > > > Anthony Crumleyhttp://commonthread.com > > > > On Sat, Apr 10, 2010 at 8:59 AM, Grary <grary.sti...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > > > I''d like to have the results of a migration file that prepopulates my > > > development database available for testing. So, right now, after the > > > usual rake migration, I can access my prepopulated data via script/ > > > console, but not in my unit tests. I''ve reviewed comments on this > > > subject but the custom rake tasks do not work or attempting a fix with > > > RAILS_ENV=test rake db:migrate as a command does not help either. Any > > > suggestion on how I can get the results of my migration available in > > > the test environment? > > > > > Thanks, > > > > > Grar > > > > > -- > > > 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<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > <rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%252Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > > > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Anthony Crumley wrote:> Grar, > > My recommendation would be to not pre-populate with a migration. I > would > create a ruby script for that and have developers run that script to get > setup. Then I would run that script in the test/test_helper.rb setup or > where ever is appropriate if I wanted that data available in my tests. >Yes. In fact, Rails 2.3 has seeding built in, and for older versions, there''s seed-fu. Seed data does not belong in migrations.> A more conventional approach would be to create fixtures with the test > data. Then you can load those fixtures into your development database > with > "rake db:fixtures:load".No. Fixtures are a broken feature of Rails and should be avoided at all costs. Use factories instead.> > Anthony Crumley > http://commonthread.comBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/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.