I don't like using javascript. I simply expose the alt field if Rails.env.test? and target the alt directly with Capybara.
I create a helper method that generates the datepicker input and hidden fields (its a bit long, and I think unnecessary to show it all). In that method I use:
def date_picker(options={})
alt_field = Rails.env.test? ? "string" : "hidden"
input = "#{ options[:f].input options[:field], as: alt_field.to_sym, input_html: {id: "#{options[
The "as: alt_field.to_sym" is what exposes the date_picker hidden alt field. I can then target the alt field input (which is the one handled by the model) in Capybara with:
fill_in 'userdoc[issued_date]', with: "2013-05-02
Easy, fairly clean, no javascript...