问题描述
在,有人问:
$ b $我有一个类似的问题,只有更糟 - 在我的情况下,生成的图像路径甚至不包括(jpg | png | gif)文件名,他们只有这些真正长的ids: / p>
I have a similar problem, only worse - in my case, the generated image paths don't even include a (jpg|png|gif) file name, they only have these really long ids:
<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" />
(使用dragonfly与mongo / gridfs)
(Using dragonfly with mongo/gridfs)
这些路径被渲染好,但我不知道如何在黄瓜/水豚步骤中找到他们:P
These paths get rendered alright, but I can't figure out how to find them in a Cucumber/Capybara step :P
任何想法?我查看了,但它们只测试图像本身的呈现
Any ideas? I looked at the Dragonfly's features, but they only test the rendering of the image itself, without detecting it's existence within an html page.
推荐答案
在(他正在努力使这更容易):
Answering my own question, after talking to Dragonfly's author (he's working on making this easier):
#route
match '/media/:dragonfly/:file_name', :to => Dragonfly[:images]
#model
class Store
include MongoMapper::Document
key :photo_uid, String
key :photo_name, String
image_accessor :photo
end
#view
<%= image_tag @store.photo.thumb('274x207#').url(:suffix => "/#{@store.photo_name}") if @store.photo %>
#cucumber
Then I should see the image "my_photo.png"
Then /^I should see the image "(.+)"$/ do |image|
page.should have_xpath("//img[contains(@src, \"#{image}\")]")
end
关键是向模型添加一个[attachment] _name字段,Dragonfly自动填充,然后将其作为后缀传递给url。除了生成的蜻蜓标识符,路由需要允许一个:file_name参数。
The key is adding an [attachment]_name field to the model, which Dragonfly populates automatically, and then passing it on as a suffix to url(). And the routes needs to allow for a :file_name param besides the generated dragonfly identifier.
这篇关于如何查找由葫芦生成的图像与黄瓜/水豚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!