cucumber/cucumber-rails — Issue #199: Capybara support for date_select :discard_day => true option
Author: beerlington
Created: 2012-03-01 03:31:29+00:00
State: open

I wanted to do this in a pull request but couldn't figure out a good way to test it with your current framework. Basically, the select_date capybara helper breaks when you use the `:discard_day => true` date_select option because it's trying to select from a field input that doesn't exist.

```erb
<%= form.date_select :submit_month, discard_day: true, order: [:month, :year] %>
```

This could be easily fixed in two ways, either change the select_date helper and add an option to ignore the day, or add another helper method (such as select_month) that ignores it.

## Changing select_date helper

```ruby
module Cucumber
module Rails
module Capybara
# This module defines methods for selecting dates and times
module SelectDatesAndTimes
# Select a Rails date. Options has must include :from => +label+
# day can be ignored using :ignore_day => true option
def select_date(date, options)
date = Date.parse(date)
base_dom_id = get_base_dom_id_from_label_tag(options[:from])

find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, :format => '%B')
find(:xpath, ".//select[@id='#{base_dom_id}_3i']").select(date.day.to_s) unless options[:ignore_day]
end
end
end
end
```

## Adding select_month helper

```ruby
module Cucumber
module Rails
module Capybara
# This module defines methods for selecting dates and times
module SelectDatesAndTimes
# Select a Rails date. Options has must include :from => +label+
def select_month(date, options)
date = Date.parse(date)
base_dom_id = get_base_dom_id_from_label_tag(options[:from])

find(:xpath, ".//select[@id='#{base_dom_id}_1i']").select(date.year.to_s)
find(:xpath, ".//select[@id='#{base_dom_id}_2i']").select(I18n.l date, :format => '%B')
end
end
end
end
end
```