Read more

Cucumber step to pick a datetime in Rails' horrible datetime_select

Henning Koch
May 12, 2015Software engineer at makandra GmbH

Please don't use the horrible datetime_select Show archive.org snapshot helper. It has a terrible UI. Always prefer to use a visual time picker like Rome Show archive.org snapshot instead.

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

In case everything has failed and you do need a Cucumber step to pick a datetime datetime_select, here it is:

When(/^I select the time (\d+)\-(\d+)\-(\d+) (\d+):(\d+) from "(.*?)"$/) do |year, month, day, hour, minute, label_text|
  label = page.find('label', text: label_text)
  id = label['for']
  select year,   from: "#{id}_1i"
  select month,  from: "#{id}_2i"
  select day,    from: "#{id}_3i"
  select hour,   from: "#{id}_4i"
  select minute, from: "#{id}_5i"
end
Posted by Henning Koch to makandra dev (2015-05-12 08:57)