我想在运行测试时禁用 ActiveAdmin。
所以我添加require: false
到 Gemfile 并检查if defined?(ActiveAdmin)
路由和初始化程序。
但是 Rails 仍然加载模型表单app/admin
,因此我收到类似于/app/admin/admin_user.rb:1:in
“:未初始化的常量 ActiveAdmin (NameError)”的错误
app/admin
将加载目录“列入黑名单”的最佳方法是什么?
我想在运行测试时禁用 ActiveAdmin。
所以我添加require: false
到 Gemfile 并检查if defined?(ActiveAdmin)
路由和初始化程序。
但是 Rails 仍然加载模型表单app/admin
,因此我收到类似于/app/admin/admin_user.rb:1:in
“:未初始化的常量 ActiveAdmin (NameError)”的错误
app/admin
将加载目录“列入黑名单”的最佳方法是什么?
# config/environments/test.rb
path_rejector = lambda { |s| s.include?("app/admin") }
# Remove the path from being loaded when Rails starts:
config.eager_load_paths = config.eager_load_paths.reject(&path_rejector)
# Remove the path from being lazily loaded
ActiveSupport::Dependencies.autoload_paths.reject!(&path_rejector)
在 config/application.rb 添加:
config.paths.delete("app/admin")
new_eager_load_paths = config.eager_load_paths.dup
new_eager_load_paths.delete("/mnt/hgfs/project/app/admin")
config.eager_load_paths = new_eager_load_paths
您必须用您的路径替换“/mnt/hgfs/project/eventmust/app/admin”,它不是很干净,但它可以工作。