2014-03-13 94 views
1

我想知道什麼是最好的方式來測試一個link_to內的動態id迭代表中的點擊?測試w /水豚/ Rspec/Rails4一個link_to與動態ID

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

而我的表將事先填充這樣

%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}" 

感謝

回答

0

水豚將匹配ID一樣的文字...

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