新 Rails 3 项目中未定义的方法 `use_transactional_fixtures=' [英] undefined method `use_transactional_fixtures=' in new Rails 3 project
问题描述
尝试在 Rails3 项目中使用 MongoDB 和 Mongoid 运行我的测试时遇到错误:
I am getting an error when trying to run my tests in a Rails3 project, using MongoDB and Mongoid:
undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class
这是一个运行在 3.0.7 上的全新项目.我的 test_helper.rb 文件正是这样:
This is a brand new project running on 3.0.7. My test_helper.rb file is exactly this:
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
self.use_transactional_fixtures = true
end
这是一个只有 ActiveRecord 的方法吗?我在其他也使用 ActiveSupport::TestCase 的 Rails 项目中没有这个问题.另外,我正在使用 Fabricator 来生成我的测试数据,但这并不能真正解释这个错误.
Is this an ActiveRecord only method? I do not have this problem in other rails projects which also use ActiveSupport::TestCase. Also, I am using Fabricator to generate my test data, but that wouldn't really explain this error.
推荐答案
问题是这样的:use_transactional_filters 是/rails/test_helper.rb 中定义的一个方法
So here's the deal: use_transactional_filters is a method defined in /rails/test_helper.rb
module ActiveRecord
module TestFixtures
extend ActiveSupport::Concern
included do
class_attribute :use_instantiated_fixtures # true, false, or :no_instances
end
end
end
所以实际上它是特定于 ActiveRecord 的.由于我没有在我的项目中使用 ActiveRecord,这没有任何效果,我必须找到另一种方法来在测试运行之间清除我的数据库.
So in fact it is ActiveRecord specific. Since I'm not using ActiveRecord in my project, this has no effect, and I'll have to find another way to clear out my database between test runs.
这篇关于新 Rails 3 项目中未定义的方法 `use_transactional_fixtures='的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!