Browse files

Merge branch 'scope_date_select' of https://github.com/twalpole/cucum…

…ber-rails into twalpole-scope_date_select
  • Loading branch information...
2 parents 104a468 + c855e44 commit 19f7e02fea7b6b11f7bac7674dfa6f8e684a2105 @aslakhellesoy aslakhellesoy committed Sep 11, 2011
Showing with 49 additions and 7 deletions.
  1. +43 −1 features/select_dates.feature
  2. +6 −6 lib/cucumber/rails/capybara/select_dates_and_times.rb
View
44 features/select_dates.feature
@@ -96,4 +96,46 @@ Feature: Select dates
"""
1 scenario (1 passed)
6 steps (6 passed)
- """
+ """
+
+ Scenario: Select correct date when scoped
+ Given I successfully run `bundle exec rails g scaffold appointment name:string when:date`
+ And I write to "features/create_appointment.feature" with:
+ """
+ Feature: Create appointments
+ Scenario: Constitution on May 17
+ Given I am on the new appointment page
+ And I fill in "Norway's constitution" for "Name"
+ And I select "2009-02-20" as the "When" date
+ And I select "2009-03-20" as the "When" date within "#extra"
+ And I press "Create Appointment"
+ Then I should see "Norway's constitution"
+ And I should see "2009-02-20"
+ """
+ And I write to "app/views/appointments/_form.html.erb" with:
+ """
+ <%= form_for(@appointment) do |f| %>
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :when, :for => "appointment_when_1i" %><br />
+ <%= f.date_select :when %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+ <% end %>
+ <div id="extra">
+ <%= label_tag 'extra_when_1i', 'When' %>
+ <%= date_select "extra", "when" %>
+ </div>
+ """
+ When I run `bundle exec rake db:migrate`
+ And I run `bundle exec rake cucumber`
+ Then it should pass with:
+ """
+ 1 scenario (1 passed)
+ 7 steps (7 passed)
+ """
View
12 lib/cucumber/rails/capybara/select_dates_and_times.rb
@@ -6,17 +6,17 @@ def select_date(field, options = {})
date = Date.parse(options[:with])
base_dom_id = get_base_dom_id_from_label_tag(field)
- 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)
+ 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
def select_time(field, options = {})
time = Time.zone.parse(options[:with])
base_dom_id = get_base_dom_id_from_label_tag(field)
- 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'))
+ 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
def select_datetime(field, options = {})
@@ -28,7 +28,7 @@ def select_datetime(field, options = {})
# @example "event_starts_at_"
def get_base_dom_id_from_label_tag(field)
- find(:xpath, "//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
+ find(:xpath, ".//label[contains(., '#{field}')]")['for'].gsub(/(_[1-5]i)$/, '')
end
end
end

0 comments on commit 19f7e02

Please sign in to comment.