Rails资产管道测试通过生产失败 [英] Rails asset pipeline tests pass production broken

查看:64
本文介绍了Rails资产管道测试通过生产失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资产管道存在以下问题.

I had the following problem with the asset pipeline.

  • 我有一封带有图片的HTML电子邮件.
  • 我进行了有关成功发送电子邮件的测试.
  • 所有测试均通过.
  • 投产时,由于HTML布局引用的是不存在的图像,因此要求发送电子邮件的功能已损坏.

这显然适用于所有预编译资产.

This obviously applies to all precompiled assets.

在我看来,突然的测试不再可靠.有什么办法可以避免这种情况再次发生?

It seems to me that suddenly tests are no longer reliable. Is there any way to avoid this situation to happen again?

推荐答案

我根据自己的情况找到了完美的解决方案.如果您设置

I found the perfect solution form my own case. If you set

 config.assets.compile = false 
 config.assets.digest = true

在测试环境中,您的测试将依赖于预编译的资产.

in test environment, your tests will rely on precompiled assets.

由于在快速开发和测试阶段每次都对资产进行预编译很烦人,因此在我看来,仅在CI上进行此配置就足够了.

Since it is annoying to precompile assets every time during quick development and testing phases, in my case it's enough to have this configuration on CI only.

您可以使用以下命令设置名为ci_config.rb的初始化程序:

You can setup an initializer called ci_config.rb with the following:

if ENV['CI'] 
  class YourApp::Application
    config.assets.compile = false
    config.assets.digest = true 
  end
end

并配置您的CI,以便在开始时运行rake资产:预编译,并在结束时运行rake资产:clean.

And configure you CI to run rake assets:precompile on start and rake assets:clean on end.

这篇关于Rails资产管道测试通过生产失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆