[英]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.