【问题标题】:Rails paperclip gem tests failingRails 回形针宝石测试失败
【发布时间】:2013-12-04 14:00:11
【问题描述】:

rake test 发出这个:

  1) Error:
ProductsControllerTest#test_should_create_product:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "lorem.jpg"
    app/controllers/products_controller.rb:27:in `create'
    test/controllers/products_controller_test.rb:27:in `block (2 levels) in <class:ProductsControllerTest>'
    test/controllers/products_controller_test.rb:26:in `block in <class:ProductsControllerTest>'

  2) Error:
ProductsControllerTest#test_should_update_product:
Paperclip::AdapterRegistry::NoHandlerError: No handler found for "lorem.jpg"
    app/controllers/products_controller.rb:46:in `block in update'
    app/controllers/products_controller.rb:45:in `update'
    test/controllers/products_controller_test.rb:44:in `block in <class:ProductsControllerTest>'

控制器看起来像这样:

def create
    @product = Product.new(product_params)
    @product.image = params[:product][:image]
    ....
end

测试控制器看起来像这样:http://pastebin.com/j3fZwJNA

我在这里做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby unit-testing testing model-view-controller


    【解决方案1】:

    Rack::Test::UploadedFile 用于测试文件和真实设备
    像这样
    Rack::Test::UploadedFile.new 'spec/fixtures/images/test.png', 'image/png'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-25
      • 2015-09-08
      相关资源
      最近更新 更多