ActiveRecord关闭后如何进行单元测试?

时间:2021-06-18 07:32:37

I have turned ActiveRecord off in my Rails app in the environment config:

我在环境配置中的Rails应用程序中关闭了ActiveRecord:

Rails::Initializer.run do |config|
  config.frameworks -= [:active_record]
end

I have models that do not extend ActiveRecord::Base and I want to unit test these models. When I run the tests I get the uninitialized constant ActiveRecord::Base error.

我的模型不扩展ActiveRecord :: Base,我想对这些模型进行单元测试。当我运行测试时,我得到未初始化的常量ActiveRecord :: Base错误。

How can I test my models when I don't have active record on?

当我没有活动记录时,如何测试我的模型?

1 个解决方案

#1


You could cheat. Add the following to your tests:

你可以作弊。将以下内容添加到测试中:

class ActiveRecord
    class Base
        end
    end

But first I'd recommend tracking down what is referring to ActiveRecord::Base. You think you aren't using it, but you may be wrong.

但首先我建议追踪指向ActiveRecord :: Base的内容。你认为你没有使用它,但你可能错了。

#1


You could cheat. Add the following to your tests:

你可以作弊。将以下内容添加到测试中:

class ActiveRecord
    class Base
        end
    end

But first I'd recommend tracking down what is referring to ActiveRecord::Base. You think you aren't using it, but you may be wrong.

但首先我建议追踪指向ActiveRecord :: Base的内容。你认为你没有使用它,但你可能错了。