我有一个已经升级到rails 4.1.8的应用程序。 我一直在四处尝试让轨道"自动管理"我的测试模式......但是,无论如何...我必须手动准备测试数据库。 我正在使用迷你测试和夹具。
这是我的test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails/capybara"
require 'minitest/rg'
Capybara.default_driver = :selenium
ActiveRecord::Migration.maintain_test_schema!
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
end
class ActiveSupport::TestCase
fixtures :all
include Sorcery::TestHelpers::Rails
include Sorcery::TestHelpers::Rails::Controller
extend MiniTest::Spec::DSL
# http://blowmage.com/2013/07/08/minitest-spec-rails4
register_spec_type self do |desc|
desc < ActiveRecord::Base if desc.is_a? Class
end
def sample_file(filename = "test_image.png")
File.new("#{Rails.root}/test/#{filename}")
end
end
重要的一行是"ActiveRecord::Migration.maintain_test_schema!...它应该自动处理测试架构。 但是,事实并非如此。 我定期拉入我的生产数据库。 之后...测试数据库将消失...所以它需要重新创建。
如果我运行:
bundle exec rake test
它将失败,并显示:
ActiveRecord::NoDatabaseError [...]
因此,测试数据库不是由 rails 自动管理的。 因为。。。它不在那里。
如果我运行捆绑执行 rake db:create 它将失败,因为开发数据库已经存在。如果我运行捆绑执行 rake db:migrate 它将执行但不会影响测试数据库。
如果我运行:
bundle exec rake db:test:prepare
它将打印:
WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test schema automatically, see the release notes for details.
测试:准备作品...我继续我快乐的测试方式。 但是,很快...测试:准备将...噗。。。逝。
问题
我错过了什么? 当倾倒和从生产中拉入时...Rails如何知道如何处理测试数据库? 这在世界上是司空见惯的...如何处理? 在这种情况下,当test:prepare在下一个rails版本中删除时会发生什么?
谢谢
rails db:test:prepare 被添加回 Rails。 我不确定是否有更多的轨道方法来接近我上面概述的内容。 我提交了一个问题来获得答案,回复只是说 db:test:prepare 被添加回来了。
https://github.com/rails/rails/issues/18045