Hi Friends, I am usiing the two databases in my project. But when i am writing the test cases,I am unable to specify the two databses,. Can u give advice ,How can i specify the two databases in testing. I hope i will get solution Regards, -Karni -- 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 -~----------~----~----~----~------~----~------~--~---
Following is what I use for the same scenario (Better solutions welcome) I set one of these up for each database I use and use the appropriate class method for each model to tell it where it resides. The XXX_DATABASE is set in the environment.rb. Just contains the database name. I don''t use database_production either, the production database is simply named database. Also, my development database is also named database since it lives on a different server. Those terms are just too long for my taste. database_prod and database_dev would have been nicer. # #If the table you are creating the model for #lives in the xxx database, make the model #extend XxxDatabase instead of ActiveRecord::Base #Also, when setting the table name ("must"), use xxx_table_name instead of set_table_name # module ARExtension def self.included(base) #:nodoc: base.extend(ClassMethods) end module ClassMethods # use xxx_table_name "table_name" in your model def xxx_table_name(value) if RAILS_ENV == "production" || RAILS_ENV == "development" set_table_name(XXX_DATABASE + "." + value) else #The test databases carry the _test at the end. set_table_name(XXX_DATABASE + "_" + RAILS_ENV + "." + value ) end end end end class XxxDatabase < ActiveRecord::Base include ARExtension end Let me know if does not make sense and I''ll explain further. When you run tests, these will be used and the appropriate databases will be used. Fredrik On Apr 9, 8:03 am, Karni <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi Friends, > > I am usiing the two databases in my project. > But when i am writing the test cases,I am unable to specify the two > databses,. > > Can u give advice ,How can i specify the two databases in testing. > > I hope i will get solution > > Regards, > -Karni > > -- > 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 -~----------~----~----~----~------~----~------~--~---
Also, I put these files in /lib, named xxx_database.rb On Apr 9, 10:10 am, "Fredrik" <fredrik.thures...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Following is what I use for the same scenario (Better solutions > welcome) > I set one of these up for each database I use and use the appropriate > class method for each model to tell it where it resides. > > The XXX_DATABASE is set in the environment.rb. Just contains the > database name. > > I don''t use database_production either, the production database is > simply named database. > Also, my development database is also named database since it lives on > a different server. Those terms are just too long for my taste. > database_prod and database_dev would have been nicer. > > # > #If the table you are creating the model for > #lives in the xxx database, make the model > #extend XxxDatabase instead of ActiveRecord::Base > #Also, when setting the table name ("must"), use xxx_table_name > instead of set_table_name > # > module ARExtension > def self.included(base) #:nodoc: > base.extend(ClassMethods) > end > > module ClassMethods > > # use xxx_table_name "table_name" in your model > def xxx_table_name(value) > if RAILS_ENV == "production" || RAILS_ENV == "development" > set_table_name(XXX_DATABASE + "." + value) > else > #The test databases carry the _test at the end. > set_table_name(XXX_DATABASE + "_" + RAILS_ENV + "." + value ) > end > end > end > end > > class XxxDatabase < ActiveRecord::Base > include ARExtension > end > > Let me know if does not make sense and I''ll explain further. When you > run tests, these will be used and the appropriate databases will be > used. > > Fredrik > > On Apr 9, 8:03 am, Karni <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Hi Friends, > > > I am usiing the two databases in my project. > > But when i am writing the test cases,I am unable to specify the two > > databses,. > > > Can u give advice ,How can i specify the two databases in testing. > > > I hope i will get solution > > > Regards, > > -Karni > > > -- > > 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 -~----------~----~----~----~------~----~------~--~---
Hi Fredrik, Very thankful to u .. I am new to ruby on rails. we have developed application in rails it is communicationg with PHP application.Everyhting is working fine. I am using the two databases in the devlopment.(i.e one is PHP application database and other one is Ruby on rails application) If u r not clear about my application i will give more information.. Please give more points use two databases in the testing I hope u will give more clear -Karni Fredrik wrote:> Following is what I use for the same scenario (Better solutions > welcome) > I set one of these up for each database I use and use the appropriate > class method for each model to tell it where it resides. > > The XXX_DATABASE is set in the environment.rb. Just contains the > database name. > > I don''t use database_production either, the production database is > simply named database. > Also, my development database is also named database since it lives on > a different server. Those terms are just too long for my taste. > database_prod and database_dev would have been nicer. > > # > #If the table you are creating the model for > #lives in the xxx database, make the model > #extend XxxDatabase instead of ActiveRecord::Base > #Also, when setting the table name ("must"), use xxx_table_name > instead of set_table_name > # > module ARExtension > def self.included(base) #:nodoc: > base.extend(ClassMethods) > end > > module ClassMethods > > # use xxx_table_name "table_name" in your model > def xxx_table_name(value) > if RAILS_ENV == "production" || RAILS_ENV == "development" > set_table_name(XXX_DATABASE + "." + value) > else > #The test databases carry the _test at the end. > set_table_name(XXX_DATABASE + "_" + RAILS_ENV + "." + value ) > end > end > end > end > > class XxxDatabase < ActiveRecord::Base > include ARExtension > end > > Let me know if does not make sense and I''ll explain further. When you > run tests, these will be used and the appropriate databases will be > used. > > Fredrik-- 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 -~----------~----~----~----~------~----~------~--~---