简体   繁体   English

使用Capybara / Rspec / Rails4使用动态ID测试link_to

[英]Test w/ Capybara/Rspec/Rails4 a link_to with dynamic id

I was wondering what would be the best way to test a click on a link_to inside of an iterated table with dynamic id? 我想知道测试带有动态ID的link_to内部的link_to单击的最佳方法是什么?

scenario 'select customer from the list' do
  sign_in_with user
  visit customers_path
  ## and here I would like to fire this action
end

And my table would be populated as such 我的桌子会这样填充

%table.table.table-striped
  %thead
    %tr
      %th
        Name
      %th

  %tbody
    - @customers.each do |customer|
      %tr
        %td
          = customer.name
        %td
          = link_to '', root_path, class: 'glyphicon glyphicon-usd pull-right', id: "customer_#{customer.id}"
          = link_to '', customer, class: 'glyphicon glyphicon-zoom-in pull-right', id: "customer_#{customer.id}"

Thanks in advance 提前致谢

Capybara will match the id the same as the text... 水豚将与文本匹配的ID ...

    @customer = Customer.all.sample
    click_link "customer_%d"%@customer.id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM