gpt4 book ai didi

ruby-on-rails - 如何加快涉及图像上传/调整大小的 Rails 单元测试?

转载 作者:行者123 更新时间:2023-12-02 04:06:02 26 4
gpt4 key购买 nike

我的应用在图像方面做了很多事情。我使用回形针将它们附加到模型上。我有大量涉及创建图像的测试(Test::Unit),这些测试运行得很慢。

我使用 FactoryGirl 在我的测试中创建模型。这就是我创建图像附件的方式:

factory :product_image_100_100 do
image File.new(File.join(::Rails.root.to_s, "/test/fixtures/images", "100_100.jpg"))
end

如何伪造图片上传或以其他方式加快速度?

最佳答案

This snippet为我工作:

require 'test_helper'
class PhotoTest < ActiveSupport::TestCase
setup do
Paperclip::Attachment.any_instance.stubs(:post_process).returns(true)
end

# tests...
end

更新。 我目前的偏好是通过将以下内容添加到我的 test_helper.rb 来全局删除 ImageMagic:
module Paperclip
def self.run(cmd, *)
case cmd
when "identify"
return "100x100"
when "convert"
return
else
super
end
end
end

(改编自 here – 顺便说一句,如果您有兴趣加快测试速度,不妨看看这篇文章)

关于ruby-on-rails - 如何加快涉及图像上传/调整大小的 Rails 单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7543736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com