我在rails 4中使用carrierwave上传图片。我在功能测试方面遇到了一些问题,特别是" image_url"在视图中使用。
我正在使用命名空间路由和相关模型。
我已经创建了一个要点:https://gist.github.com/lperry65/f72260a17f29fae18544
这是我在运行以下产品测试时遇到的错误:
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:products)
end
1) Error:
Admin::ProductsControllerTest#test_should_get_index:
ActionView::Template::Error: undefined method `image_url' for nil:NilClass
app/views/admin/products/index.html.erb:9:in `block in _app_views_admin_products_index_html_erb__290306839054085465_2161027740'
app/views/admin/products/index.html.erb:6:in `_app_views_admin_products_index_html_erb__290306839054085465_2161027740'
test/controllers/admin/products_controller_test.rb:10:in `block in <class:ProductsControllerTest>'
这是因为视图中的这一行:
<td><%= image_tag product.images[0].image_url(:thumb).to_s %></td>
这是我第一次使用carrierwave,所以非常感谢任何帮助:)