diff --git a/History.txt b/History.txt index b952507..db7eae6 100644 --- a/History.txt +++ b/History.txt @@ -12,7 +12,6 @@ * Minor enhancements * Add Webrat.root method for cross-framework support (Krzysztof Zylawy) - * Add #select_date for quickly filling out Rails-style date fields (Alex Lang) * Support selecting options by their values (Alex Lang) * Support for clicking areas of an image map (Alex Lang) * Add should_see and should_not_see for verifying HTML response bodys diff --git a/lib/webrat/core/form.rb b/lib/webrat/core/form.rb index de36093..4522710 100644 --- a/lib/webrat/core/form.rb +++ b/lib/webrat/core/form.rb @@ -17,12 +17,14 @@ module Webrat nil end - def find_select_option(option_text, field_name_pattern = nil) + def find_select_option(option_text) select_fields = fields_by_type([SelectField]) - select_fields.select{|field| field_name_pattern.nil? || field.matches_name?(field_name_pattern) || field.matches_id?(field_name_pattern)}.each do |select_field| + + select_fields.each do |select_field| result = select_field.find_option(option_text) return result if result end + nil end diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index 600a7b0..99b95c6 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -12,22 +12,6 @@ module Webrat @selector = selector end - def selects_date(date_string, options = {}) - id_or_name = options[:from] - date = Date.parse date_string - - year_option = find_select_option(date.year.to_s, /#{id_or_name.to_s}.*1i/) - month_option = find_select_option(date.month.to_s, /#{id_or_name.to_s}.*2i/) - day_option = find_select_option(date.day.to_s, /#{id_or_name.to_s}.*3i/) - - flunk("Could not find date picker for #{date_string}") if year_option.nil? || month_option.nil? || day_option.nil? - year_option.choose - month_option.choose - day_option.choose - end - - alias_method :select_date, :selects_date - # Verifies an input field or textarea exists on the current page, and stores a value for # it which will be sent when the form is submitted. # diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index ab89e50..04e25af 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -151,7 +151,6 @@ module Webrat def_delegators :current_scope, :uncheck, :unchecks def_delegators :current_scope, :choose, :chooses def_delegators :current_scope, :select, :selects - def_delegators :current_scope, :select_date, :selects_date def_delegators :current_scope, :attach_file, :attaches_file def_delegators :current_scope, :click_area, :clicks_area def_delegators :current_scope, :click_link, :clicks_link diff --git a/spec/api/selects_date_spec.rb b/spec/api/selects_date_spec.rb deleted file mode 100644 index cad52ff..0000000 --- a/spec/api/selects_date_spec.rb +++ /dev/null @@ -1,111 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") - -describe "date_selects" do - before do - @session = Webrat::TestSession.new - @example_date_select = <<-EOS -
-
- - - - -
- EOS - end - - - it "should fail if option not found" do - @session.response_body = @example_date_select - lambda { @session.selects_date "2008-07-13"}.should raise_error - end - - it "should fail if option not found in list specified by element name" do - @session.response_body = @example_date_select - lambda { @session.selects_date "2008-07-13", :from => "created_at" }.should raise_error - end - - it "should fail if specified list not found" do - @session.response_body = <<-EOS -
- -
- EOS - - lambda { @session.selects_date "2003-12-01", :from => "created_at" }.should raise_error - end - - it "should send value from option" do - @session.response_body = <<-EOS -
-
- - - -
- - - - -
- EOS - @session.should_receive(:post).with("/login", "created_at(1i)" => "2003", 'created_at(2i)' => '12', 'created_at(3i)' => '1', "updated_at(1i)" => "", 'updated_at(2i)' => '', 'updated_at(3i)' => '') - @session.selects_date '2003-12-01', :from => "created_at" - @session.clicks_button - end - - it "should work without specifying the field name or label" do - @session.response_body = @example_date_select - @session.should_receive(:post).with("/login", "created_at(1i)" => "2003", 'created_at(2i)' => '12', 'created_at(3i)' => '1') - @session.selects_date '2003-12-01' - @session.clicks_button - end - - it "should correctly set day and month when there are the same options available" do - @session.response_body = <<-EOS -
-
- - - - -
- EOS - @session.should_receive(:post).with("/login", "created_at(1i)" => "2003", 'created_at(2i)' => '12', 'created_at(3i)' => '1') - @session.selects_date '2003-12-01' - @session.clicks_button - end - -end