> Sure, I'd like to write some tests and I had an impression that when > accessing a class that used mystore connection, RSpec tried to use the > default connection defined in test group of database.yml. Is the way I'm > truing to do that in testing correct ?
No, RSpec doesn’t do *any* database configuration, Rails will use the environment named configuration by default, but `establish_connection` *should* override it. If it’s not behaving as you expect you might want to check that Rails is loading your files correctly (as until `establish_connection` is called you won’t have configured the other database). Cheers Jon Rowe --------------------------- [email protected] jonrowe.co.uk On Wednesday, 27 June 2018 at 14:48, Serguei Cambour wrote: > Thank you John ! > What I need is to migrate some data from one DB (mystore connection) to > another. That's why I had to write some specific Rake tasks to match tables > attributes to be imported (mystore connection) to another DB defined in > development group in database.yml. Sure, I'd like to write some tests and I > had an impression that when accessing a class that used mystore connection, > RSpec tried to use the default connection defined in test group of > database.yml. Is the way I'm truing to do that in testing correct ? Thank you. > > > On Wed, 27 Jun 2018 at 15:43, Jon Rowe <[email protected] > (mailto:[email protected])> wrote: > > Sorry I misunderstood your question! > > > > What you need to do is specify multiple environments for your second > > database, so you can establish an environment specific connection. As you > > can see from your own configuration thats the standard pattern, so you > > could then use `establish_connection` with the appropriate db e.g. > > `establish_connection(:”mystore_#{Rails.env}”)` and have a test version of > > your second DB > > > > Cheers > > Jon Rowe > > --------------------------- > > [email protected] (mailto:[email protected]) > > jonrowe.co.uk (http://jonrowe.co.uk) > > > > > > On Wednesday, 27 June 2018 at 14:06, belgoros wrote: > > > > > I had to modify my base class by adding > > > unless Rails.env.test? > > > > > > > > > condition: > > > > > > > > > module MystoreMigration > > > class MystoreModel < ActiveRecord::Base > > > self.abstract_class = true > > > establish_connection(:mystore) unless Rails.env.test? > > > end > > > end > > > > > > > > > All other model classes used by rake tasks inherit from the above model. > > > In this case I'll have to mock all the DB calls related to this rake task > > > to avoid it to establish mystore connection defined in `database.yml` > > > and used by all the tasks models. > > > > > > > > > > > > On Wednesday, 27 June 2018 14:16:22 UTC+2, Jon Rowe wrote: > > > > Hi Javix > > > > > > > > RSpec itself has no database integration so it's certainly possible, > > > > you'll need to either configure a connection manually to talk through > > > > or use however you'd normally talk to your other database. > > > > > > > > If you’re using rspec-rails you’ll need to figure out how Rails does > > > > it’s transactional testing for multiple databases, but most 3rd party > > > > gems support “cleaning” multiple databases, including DatabaseCleaner. > > > > > > > > HTH > > > > Jon > > > > > > > > On Wed, 27 Jun 2018 at 09:53, Javix <[email protected]> wrote: > > > > > I need to execute some rake tasks agains a database other than > > > > > defined in database.yml, test group. Here is how database.yml looks > > > > > like: > > > > > > > > > > default: &default > > > > > adapter: postgresql > > > > > encoding: unicode > > > > > user: postgres > > > > > password: > > > > > pool: 5 > > > > > > > > > > > > > > > development: > > > > > <<: *default > > > > > database: decastore_development > > > > > host: <%= ENV['DECASTORE_DATABASE_HOST'] %> > > > > > > > > > > > > > > > test: > > > > > <<: *default > > > > > database: decastore_test > > > > > host: <%= ENV['DECASTORE_DATABASE_HOST'] %> > > > > > > > > > > > > > > > production: > > > > > <<: *default > > > > > host: <%= ENV['DECASTORE_DATABASE_HOST'] %> > > > > > database: XXXX > > > > > username: XXXXX > > > > > password: <%= ENV['DECASTORE_DATABASE_PASSWORD'] %> > > > > > > > > > > > > > > > mystore: > > > > > adapter: oracle_enhanced > > > > > host: <%= ENV['mystore_db_host']%> > > > > > port: <%= ENV['mystore_db_port']%> > > > > > database: <%= ENV['mystore_db_name']%> > > > > > username: <%= ENV['mystore_db_user']%> > > > > > password: <%= ENV['mystore_db_password']%> > > > > > > > > > > > > > > > Is it possible to mix 2 database settings when running tests or I > > > > > have to mock it everywhere ? > > > > > Thank you. > > > > > > > > > > > > > > > -- > > > > > You received this message because you are subscribed to the Google > > > > > Groups "rspec" group. > > > > > To unsubscribe from this group and stop receiving emails from it, > > > > > send an email to [email protected]. > > > > > To post to this group, send email to [email protected]. > > > > > To view this discussion on the web visit > > > > > https://groups.google.com/d/msgid/rspec/f723fd63-26b2-4ff7-a9ff-b8a3a69567f3%40googlegroups.com > > > > > > > > > > (https://groups.google.com/d/msgid/rspec/f723fd63-26b2-4ff7-a9ff-b8a3a69567f3%40googlegroups.com?utm_medium=email&utm_source=footer). > > > > > For more options, visit https://groups.google.com/d/optout. > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "rspec" group. > > > To unsubscribe from this group and stop receiving emails from it, send an > > > email to [email protected] > > > (mailto:[email protected]). > > > To post to this group, send email to [email protected] > > > (mailto:[email protected]). > > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/rspec/b5fa5aad-7a2a-4b53-875f-8bda30682c1d%40googlegroups.com > > > > > > (https://groups.google.com/d/msgid/rspec/b5fa5aad-7a2a-4b53-875f-8bda30682c1d%40googlegroups.com?utm_medium=email&utm_source=footer). > > > For more options, visit https://groups.google.com/d/optout. > > > > -- > > You received this message because you are subscribed to a topic in the > > Google Groups "rspec" group. > > To unsubscribe from this topic, visit > > https://groups.google.com/d/topic/rspec/sbRqzLR_Lug/unsubscribe. > > To unsubscribe from this group and all its topics, send an email to > > [email protected] > > (mailto:[email protected]). > > To post to this group, send email to [email protected] > > (mailto:[email protected]). > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/rspec/74587C34A93D431CB66AE4B35D84EC2B%40jonrowe.co.uk > > > > (https://groups.google.com/d/msgid/rspec/74587C34A93D431CB66AE4B35D84EC2B%40jonrowe.co.uk?utm_medium=email&utm_source=footer). > > For more options, visit https://groups.google.com/d/optout. > -- > You received this message because you are subscribed to the Google Groups > "rspec" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > (mailto:[email protected]). > To post to this group, send email to [email protected] > (mailto:[email protected]). > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/CAJGQ%3DvbsA2GkxtTuUCqKSChAe8YRf-Yeafv68qgSFvQ5X8qCXw%40mail.gmail.com > > (https://groups.google.com/d/msgid/rspec/CAJGQ%3DvbsA2GkxtTuUCqKSChAe8YRf-Yeafv68qgSFvQ5X8qCXw%40mail.gmail.com?utm_medium=email&utm_source=footer). > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "rspec" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/84E9FF30E50443B1A9185FBC86D08D17%40jonrowe.co.uk. For more options, visit https://groups.google.com/d/optout.
