1

我目前正在尝试在具有两个数据库连接的 Rails 应用程序上执行一些测试。当然,我不想在每次执行测试时都删除第二个数据库,如果环境是“测试”,我已经设置了一个连接到另一个第二个数据库的机制(见下文)。

我的问题:我怎么能告诉 rake 测试也在rake db:test:prepare第二个 DB 上执行?

这个查询已经触及我的问题,但不能完全帮助我。

一些代码来解释:

连接到第二个数据库的我的 ActiveRecord 类继承自以下类 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

(是的,我知道......该架构不遵循 Rails 约定。这是一个遗留的)

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

4

0 回答 0