jeudi 29 janvier 2015

Rails-4 missing dom_id method in cucumber step definition


  • OS = CentOS-6.6

  • Ruby = 2.0.0

  • Rails = 4.2.0

  • Cucumber = 3.1.18

  • Capybara = 2.4.4


We are moving an existing RoR-3.2 to 4.2. We have added in the necessary gems to ease the pain of many of the deprecations:



# Temporary gems to get to Rails4
gem 'protected_attributes'
gem 'rails-observers'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'
gem 'activerecord-deprecated_finders'
gem 'dynamic_form'


However, I am somewhat stymied with this situation involving one of our Cucumber step_definitions:



When /deletes? the "(.*)" correspondent/ do |row|
this_correspondent = Correspondent.find_by_correspondent_common_name(
"my correspondent number #{row.hll_words_to_i}")
within("td#" + dom_id( this_correspondent, :delete )) do
click_link( "Destroy Correspondent" )
end
end


Which produces this error:



(::) failed steps (::)

undefined method `dom_id' for
#<Cucumber::Rails::World:0x000000089c92f0> (NoMethodError)
./features/app/models/correspondents/step_definitions
/correspondent_steps.rb:43:in
`/deletes? the "(.*)" correspondent/'
features/app/models/correspondents/correspondent.feature:68:in
`When they delete the "first" correspondent'


Testing this view code:



<% for correspondent in @correspondents %>
<tr id="<%=dom_id(correspondent, :row_1)%>">
<td><%=h correspondent.correspondent_common_name.titlecase -%></td>
<td></td>
<td><%=h correspondent.correspondent_legal_form -%></td>
<!-- See http://ift.tt/1Dl518s -->
<!-- and http://ift.tt/1Dl518s -->
<td><%= "%06d" % correspondent.id -%></td>
<td id="<%=dom_id(correspondent, :show)%>"><%= link_to 'Show Correspondent',
correspondent -%></td>
<td id="<%=dom_id(correspondent, :edit)%>"><%= link_to 'Edit Correspondent',
edit_correspondent_path(correspondent) -%></td>
<td id="<%=dom_id(correspondent, :delete)%>"><%= link_to 'Destroy Correspondent',
correspondent, :confirm => 'Are you sure?', :method => :delete -%>
</td>
</tr>


The Rails upgrade guide says this:



Rails 4.0 deprecates the dom_id and dom_class methods in controllers (they are fine in views). You will need to include the ActionView::RecordIdentifier module in controllers requiring this feature.



Which I am fine with. I cannot find any occurrence in the existing code base where either method is explicitly used outside of view templates.


However, I am not sure how I am supposed to test for view elements using dom_id() using Cucumber. Is there something I need to add to the development/test gems to get back this behaviour?


Aucun commentaire:

Enregistrer un commentaire