module Cucumber::Rails::Capybara::SelectDatesAndTimes

This module defines methods for selecting dates and times

Public Instance Methods

select_date(date, options) click to toggle source

Select a Rails date. Options hash must include :from => label

# File lib/cucumber/rails/capybara/select_dates_and_times.rb, line 7
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)
end
select_datetime(datetime, options) click to toggle source

Select a Rails datetime. Options hash must include :from => label

# File lib/cucumber/rails/capybara/select_dates_and_times.rb, line 26
def select_datetime(datetime, options)
  select_date(datetime, options)
  select_time(datetime, options)
end
select_time(time, options) click to toggle source

Select a Rails time. Options hash must include :from => label

# File lib/cucumber/rails/capybara/select_dates_and_times.rb, line 17
def select_time(time, options)
  time        = Time.zone.parse(time)
  base_dom_id = get_base_dom_id_from_label_tag(options[:from])

  find(:xpath, ".//select[@id='#{base_dom_id}_4i']").select(time.hour.to_s.rjust(2, '0'))
  find(:xpath, ".//select[@id='#{base_dom_id}_5i']").select(time.min.to_s.rjust(2,  '0'))
end

Private Instance Methods

get_base_dom_id_from_label_tag(field) click to toggle source

@example “event_starts_at_”

# File lib/cucumber/rails/capybara/select_dates_and_times.rb, line 34
def get_base_dom_id_from_label_tag(field)
  find(:xpath, ".//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
end