Greg Hauptmann
2008-Nov-06 09:08 UTC
how can I run a line of rails code within the "test.rb" environment file???
Hi, How to I get a rails line of code that normally works within a rails mode, but but have it run within "test.rb" environment file. For example to get the following to run: RecurringType.create(:name => "TYPE_BASIC") PS. Or in general how to get a normal rails line of code to run in the "test.rb" file (i.e. only for when starting up in test mode). I get "ActiveRecord::ConnectionNotEstablished" when I include "RecurringType.create(:name => "TYPE_BASIC")". 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-06 10:17 UTC
Re: how can I run a line of rails code within the "test.rb" environment file???
On 6 Nov 2008, at 09:08, Greg Hauptmann wrote:> > Hi, > > How to I get a rails line of code that normally works within a rails > mode, but but have it run within "test.rb" environment file. For > example to get the following to run: > > RecurringType.create(:name => "TYPE_BASIC") > > PS. Or in general how to get a normal rails line of code to run in the > "test.rb" file (i.e. only for when starting up in test mode). I get > "ActiveRecord::ConnectionNotEstablished" when I include > "RecurringType.create(:name => "TYPE_BASIC")". >You need to make your code run after the framework has been fully initialized (which it isn''t when test.rb runs). Application initializers (files in config/initializers) run after this as do config.after_initialize blocks. Fred> 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Nov-06 10:27 UTC
Re: how can I run a line of rails code within the "test.rb" environment file???
thanks Fred - I hadn''t come across these before.. So can I create a "test.rb" file in the "initializers" directory such that it would only run it for the "test" environment? Or if not what would you recommend re approach to ensure the code was only run when in a specific environment (e.g. ''test'' in this case)? Thanks On Thu, Nov 6, 2008 at 8:17 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 6 Nov 2008, at 09:08, Greg Hauptmann wrote: > >> >> Hi, >> >> How to I get a rails line of code that normally works within a rails >> mode, but but have it run within "test.rb" environment file. For >> example to get the following to run: >> >> RecurringType.create(:name => "TYPE_BASIC") >> >> PS. Or in general how to get a normal rails line of code to run in the >> "test.rb" file (i.e. only for when starting up in test mode). I get >> "ActiveRecord::ConnectionNotEstablished" when I include >> "RecurringType.create(:name => "TYPE_BASIC")". >> > You need to make your code run after the framework has been fully > initialized (which it isn''t when test.rb runs). Application > initializers (files in config/initializers) run after this as do > config.after_initialize blocks. > > Fred >> 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Nov-06 10:45 UTC
Re: how can I run a line of rails code within the "test.rb" environment file???
On 6 Nov 2008, at 10:27, Greg Hauptmann wrote:> > thanks Fred - I hadn''t come across these before.. > > So can I create a "test.rb" file in the "initializers" directory such > that it would only run it for the "test" environment? Or if not what > would you recommend re approach to ensure the code was only run when > in a specific environment (e.g. ''test'' in this case)? >stuff in config/initializers is always run, but you can of course stick a if RAILS_ENV == ''foo'' in there. I tend to keep the stuff in their group by purpose. The config.after_initialize thing wouldn''t require you to test what the environment is. Fred> Thanks > > On Thu, Nov 6, 2008 at 8:17 PM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On 6 Nov 2008, at 09:08, Greg Hauptmann wrote: >> >>> >>> Hi, >>> >>> How to I get a rails line of code that normally works within a rails >>> mode, but but have it run within "test.rb" environment file. For >>> example to get the following to run: >>> >>> RecurringType.create(:name => "TYPE_BASIC") >>> >>> PS. Or in general how to get a normal rails line of code to run in >>> the >>> "test.rb" file (i.e. only for when starting up in test mode). I get >>> "ActiveRecord::ConnectionNotEstablished" when I include >>> "RecurringType.create(:name => "TYPE_BASIC")". >>> >> You need to make your code run after the framework has been fully >> initialized (which it isn''t when test.rb runs). Application >> initializers (files in config/initializers) run after this as do >> config.after_initialize blocks. >> >> Fred >>> 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Nov-06 10:51 UTC
Re: how can I run a line of rails code within the "test.rb" environment file???
Fred - re "The config.after_initialize thing wouldn''t require you to test what the environment is" - what do you mean by this? where would the code go in this case such that there would be a way to have it only run for the ''test'' environment? On Thu, Nov 6, 2008 at 8:45 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 6 Nov 2008, at 10:27, Greg Hauptmann wrote: > >> >> thanks Fred - I hadn''t come across these before.. >> >> So can I create a "test.rb" file in the "initializers" directory such >> that it would only run it for the "test" environment? Or if not what >> would you recommend re approach to ensure the code was only run when >> in a specific environment (e.g. ''test'' in this case)? >> > stuff in config/initializers is always run, but you can of course > stick a if RAILS_ENV == ''foo'' in there. I tend to keep the stuff in > their group by purpose. > The config.after_initialize thing wouldn''t require you to test what > the environment is. > Fred >> Thanks >> >> On Thu, Nov 6, 2008 at 8:17 PM, Frederick Cheung >> <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>> >>> On 6 Nov 2008, at 09:08, Greg Hauptmann wrote: >>> >>>> >>>> Hi, >>>> >>>> How to I get a rails line of code that normally works within a rails >>>> mode, but but have it run within "test.rb" environment file. For >>>> example to get the following to run: >>>> >>>> RecurringType.create(:name => "TYPE_BASIC") >>>> >>>> PS. Or in general how to get a normal rails line of code to run in >>>> the >>>> "test.rb" file (i.e. only for when starting up in test mode). I get >>>> "ActiveRecord::ConnectionNotEstablished" when I include >>>> "RecurringType.create(:name => "TYPE_BASIC")". >>>> >>> You need to make your code run after the framework has been fully >>> initialized (which it isn''t when test.rb runs). Application >>> initializers (files in config/initializers) run after this as do >>> config.after_initialize blocks. >>> >>> Fred >>>> 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Nov-06 11:04 UTC
Re: how can I run a line of rails code within the "test.rb" environment file???
arr got it: config.after_initialize do # xxx end On Thu, Nov 6, 2008 at 8:51 PM, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Fred - re "The config.after_initialize thing wouldn''t require you to > test what the environment is" - what do you mean by this? where would > the code go in this case such that there would be a way to have it > only run for the ''test'' environment? > > On Thu, Nov 6, 2008 at 8:45 PM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> On 6 Nov 2008, at 10:27, Greg Hauptmann wrote: >> >>> >>> thanks Fred - I hadn''t come across these before.. >>> >>> So can I create a "test.rb" file in the "initializers" directory such >>> that it would only run it for the "test" environment? Or if not what >>> would you recommend re approach to ensure the code was only run when >>> in a specific environment (e.g. ''test'' in this case)? >>> >> stuff in config/initializers is always run, but you can of course >> stick a if RAILS_ENV == ''foo'' in there. I tend to keep the stuff in >> their group by purpose. >> The config.after_initialize thing wouldn''t require you to test what >> the environment is. >> Fred >>> Thanks >>> >>> On Thu, Nov 6, 2008 at 8:17 PM, Frederick Cheung >>> <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>> >>>> On 6 Nov 2008, at 09:08, Greg Hauptmann wrote: >>>> >>>>> >>>>> Hi, >>>>> >>>>> How to I get a rails line of code that normally works within a rails >>>>> mode, but but have it run within "test.rb" environment file. For >>>>> example to get the following to run: >>>>> >>>>> RecurringType.create(:name => "TYPE_BASIC") >>>>> >>>>> PS. Or in general how to get a normal rails line of code to run in >>>>> the >>>>> "test.rb" file (i.e. only for when starting up in test mode). I get >>>>> "ActiveRecord::ConnectionNotEstablished" when I include >>>>> "RecurringType.create(:name => "TYPE_BASIC")". >>>>> >>>> You need to make your code run after the framework has been fully >>>> initialized (which it isn''t when test.rb runs). Application >>>> initializers (files in config/initializers) run after this as do >>>> config.after_initialize blocks. >>>> >>>> Fred >>>>> 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 -~----------~----~----~----~------~----~------~--~---