私は現在、2つのデータベース接続を持つRailsアプリでいくつかのテストを実行しようとしています。もちろん、テストを実行するたびに2番目のデータベースを削除したくないので、環境が「テスト」の場合に別の2番目のDBに接続するメカニズムを設定しました(以下を参照)。
rake db:test:prepare
私の質問: 2番目のDBでも実行するようにrake testに指示するにはどうすればよいですか?
このクエリはすでに私の問題に触れましたが、完全には役に立ちませんでした。
説明するいくつかのコード:
MyActiveRecord-2番目のデータベースに接続するクラスは次のクラスInformixConnectから継承します。
class InformixConnect < ActiveRecord::Base
self.abstract_class = true
case Rails.env
when 'production', 'development'
establish_connection :development_informix
when 'test'
establish_connection :test_informix_dummy
else
raise "Please specify a correct informix Environment."
end
end
お気に入り
class RenewalNotify < InformixConnect
set_table_name :renewal_notify
set_primary_key :renewal_notify_id
end
(はい、私は知っています...スキーマはレールの規則に従っていません。それはレガシーのものです)
database.ymlには
...
development:
adapter: postgresql
database: rails_development
host: 127.0.0.1
reconnect: true
username: rails
password: guessone
...
development_informix:
adapter: informix
database: SOMETHING
username: yyy
password: yyy
test_informix_dummy:
adapter: sqlite3
database: db/test_informix_dummy.sqlite3
...
# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test: &TEST
adapter: sqlite3
database: db/test.db
verbosity: silent
timeout: 5000
したがって、実行するたびに「test_informix_dummy」データベースを設定する必要があります。rake test