【问题标题】:How do I find an image generated by Dragonfly with Cucumber/Capybara?如何找到 Dragonfly 使用 Cucumber/Capybara 生成的图像?
【发布时间】:2011-03-16 20:16:29
【问题描述】:

How do I find an image on a page with Cucumber/Capybara的解决方案的cmets中,有人问:

我似乎不知道如何获得这个 使用由生成的 URL 蜻蜓。它们看起来像这样: /media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中 5x5.jpg 是我的文件名。我有 尝试过类似的东西: //img[@src="/media//#{image}?s=*"] 但它不起作用。有任何提示吗? – Ramon Tayag 2 月 25 日 4:18

我也有类似的问题,只是更糟 - 在我的情况下,生成的图像路径甚至不包含 (jpg|png|gif) 文件名,它们只有这些非常长的 id:

<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" />

(将蜻蜓与 mongo/gridfs 一起使用)

这些路径可以正常渲染,但我不知道如何在 Cucumber/Capybara 步骤中找到它们:P

有什么想法吗?我查看了Dragonfly's features,但他们只测试图像本身的渲染,而没有检测到它是否存在于 html 页面中。

【问题讨论】:

    标签: ruby-on-rails cucumber capybara image-upload dragonfly-gem


    【解决方案1】:

    talking to Dragonfly's author 之后回答我自己的问题(他正在努力使这更容易):

    #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 参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多