我有非铁路应用的黄瓜测试。
我的项目中没有database.yml,并且由于某些原因不想拥有它(连接设置以不同的格式存储)。
我有几个数据库模型,定义如
class MyBase < ActiveRecord::Base
self.abstract_class = true
def self.some_extra_methods
end
end
class DatabaseA < MyBase
self.abstract_class = true
establish_connection ($configA)
end
class DatabaseB < MyBase
self.abstract_class = true
establish_connection ($configB)
end
# if i will not connect ActiveRecord::Base to something i get ActiveRecord::ConnectionNotEstablished errors
# is there a better solution?
ActiveRecord::Base.establish_connection $configC;
class TableA < DatabaseA
self.table_name = :table_a
self.primary_key = :id
end
#... and other tables
class TableB < DatabaseB
self.table_name = :table_b
self.primary_key = :id
end
#... and other tables
现在要清理数据库我正在尝试使用以下代码。 我没有database.yml所以我只是传递模型。
DatabaseCleaner[:active_record, {:model => DatabaseA} ].strategy = :truncation
DatabaseCleaner[:active_record, {:model => DatabaseB} ].strategy = :truncation
Before do
DatabaseCleaner.start
end
After do
DatabaseCleaner.clean
end
但它只清理由ActiveRecord :: Base连接的数据库,而不是DatabaseA&amp; DatabaseB 怎么了?