如何查找由葫芦生成的图像与黄瓜/水豚? [英] How do I find an image generated by Dragonfly with Cucumber/Capybara?

查看:161
本文介绍了如何查找由葫芦生成的图像与黄瓜/水豚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在带有黄瓜/水豚的页面上找到图片,有人问:


我似乎无法得到这个
如何使用
生成的URL。它们看起来像这样:
/media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中5x5.jpg是我的文件名。我有
尝试类似:
// img [@src =/ media / / #{image}?s = *]
不工作。有什么提示? - Ramon Tayag Feb 25 at 4:18

I can't seem to figure how to get this to work with URLs generated by Dragonfly. They look like this: /media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000, where 5x5.jpg is my file name. I've tried something like: //img[@src="/media//#{image}?s=*"] but it doesn't work. Got any tips? – Ramon Tayag Feb 25 at 4:18

$ 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

任何想法?我查看了 Dragonfly的功能,但它们只测试图像本身的呈现

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.

推荐答案

向Dragonfly的作者(他正在努力使这更容易):

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.

这篇关于如何查找由葫芦生成的图像与黄瓜/水豚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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