Sha256: 1e052f059f35d98a28911eb9146d3fe886c19c5bb4b1b352dff449792064a806

Contents?: true

Size: 1.32 KB

Versions: 76

Compression:

Stored size: 1.32 KB

Contents

###
# Unscrupulously stolen from: https://raw.github.com/cucumber/cucumber-rails/master/lib/cucumber/rails/capybara/select_dates_and_times.rb
#
def select_date(date, options = {})
  date        = Time.parse(date)
  base_dom_id = get_base_dom_id_from_label_tag(options[:from])

  page.execute_script %Q{$("##{base_dom_id}_1i").val("#{date.strftime('%Y')}")}
  page.execute_script %Q{$("##{base_dom_id}_2i").val("#{date.strftime('%m')}")}
  page.execute_script %Q{$("##{base_dom_id}_3i").val("#{date.strftime('%d')}")}
  page.execute_script %Q{$("##{base_dom_id}_datepicker").val("#{date.strftime('%m/%d/%Y')}")}
  page.execute_script %Q{$("##{base_dom_id}_datepicker").change()}
end

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.strftime '%I %p')
  find(:xpath, ".//select[@id='#{base_dom_id}_5i']").select(time.min.to_s.rjust(2,  '0'))

  page.execute_script %Q{$("##{base_dom_id}_datepicker").change()}
end

def select_datetime(datetime, options = {})
  select_date(datetime, options)
  select_time(datetime, options)
end

private

# @example "event_starts_at_"
def get_base_dom_id_from_label_tag(field)
  find(:xpath, ".//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
end

Version data entries

76 entries across 76 versions & 1 rubygems

Version Path
rspectacular-0.59.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.58.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.57.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.56.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.55.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.54.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.53.1 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.53.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.52.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.51.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.50.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.49.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.48.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.47.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.46.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.45.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.44.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.43.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.42.0 lib/rspectacular/helpers/date_time_select.rb
rspectacular-0.41.0 lib/rspectacular/helpers/date_time_select.rb