From 740bb293e33bf88f1c06e194ea087723298b5e6c Mon Sep 17 00:00:00 2001 From: Matthew Ford Date: Thu, 26 Feb 2009 14:39:10 +0000 Subject: [PATCH 1/2] Fix for #161 When using Rails 2.3 it uses Rack::Utils to parse params --- History.txt | 1 + lib/webrat/core/elements/field.rb | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/History.txt b/History.txt index de7cf54..00d632f 100644 --- a/History.txt +++ b/History.txt @@ -2,6 +2,7 @@ * Minor enhancements + * When using Rails 2.3, use Rack::Utils to parse params (Matthew Ford) * Initial Merb and Sinatra compatibility for Selenium mode (Corey Donohoe) * Add application_framework config for Selenium mode to determine how to start and stop the app server (Corey Donohoe) diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index ef3fd2b..fc3f9ec 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -80,7 +80,7 @@ module Webrat case Webrat.configuration.mode when :rails - rails_request_parser.parse_query_parameters("#{name}=#{escaped_value}") + parse_rails_request_params("#{name}=#{escaped_value}") when :merb ::Merb::Parse.query("#{name}=#{escaped_value}") else @@ -98,12 +98,15 @@ module Webrat protected - def rails_request_parser + def parse_rails_request_params(params) if defined?(ActionController::AbstractRequest) - ActionController::AbstractRequest - else + ActionController::AbstractRequest.parse_query_parameters(params) + elsif defined?(ActionController::UrlEncodedPairParser) # For Rails > 2.2 - ActionController::UrlEncodedPairParser + ActionController::UrlEncodedPairParser.parse_query_parameters(params) + else + # For Rails > 2.3 + Rack::Utils.parse_nested_query(params) end end From 72123c1cece70b77b65fd3b5f4f99ef8fbb8f2cd Mon Sep 17 00:00:00 2001 From: Luke Melia Date: Sun, 1 Mar 2009 01:44:35 -0500 Subject: [PATCH 2/2] When faced with a label with no for attribute, that contains a hidden field and another field, as can be the case in Rails 2.3's checkbox view, webrat now locates the non-hidden field. --- History.txt | 3 +++ lib/webrat/core/elements/field.rb | 4 ++++ lib/webrat/core/elements/label.rb | 2 +- spec/public/check_spec.rb | 19 +++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/History.txt b/History.txt index 00d632f..e7ae9ce 100644 --- a/History.txt +++ b/History.txt @@ -2,6 +2,9 @@ * Minor enhancements + * When faced with a label with no for attribute, that contains a hidden field + and another field, as can be the case in Rails 2.3's checkbox view, + webrat now locates the non-hidden field. (Luke Melia) * When using Rails 2.3, use Rack::Utils to parse params (Matthew Ford) * Initial Merb and Sinatra compatibility for Selenium mode (Corey Donohoe) * Add application_framework config for Selenium mode to determine how to diff --git a/lib/webrat/core/elements/field.rb b/lib/webrat/core/elements/field.rb index fc3f9ec..8efc24a 100644 --- a/lib/webrat/core/elements/field.rb +++ b/lib/webrat/core/elements/field.rb @@ -15,6 +15,10 @@ module Webrat def self.xpath_search [".//button", ".//input", ".//textarea", ".//select"] end + + def self.xpath_search_excluding_hidden + [".//button", ".//input[ @type != 'hidden']", ".//textarea", ".//select"] + end def self.field_classes @field_classes || [] diff --git a/lib/webrat/core/elements/label.rb b/lib/webrat/core/elements/label.rb index 3f8388b..0450f20 100644 --- a/lib/webrat/core/elements/label.rb +++ b/lib/webrat/core/elements/label.rb @@ -21,7 +21,7 @@ module Webrat def field_element if for_id.blank? - Webrat::XML.xpath_at(@element, *Field.xpath_search) + Webrat::XML.xpath_at(@element, *Field.xpath_search_excluding_hidden) else Webrat::XML.css_search(@session.current_dom, "#" + for_id).first end diff --git a/spec/public/check_spec.rb b/spec/public/check_spec.rb index 4366a03..be12349 100644 --- a/spec/public/check_spec.rb +++ b/spec/public/check_spec.rb @@ -169,4 +169,23 @@ describe "uncheck" do check 'Option 2' click_button end + + it "should uncheck rails style checkboxes nested inside a label" do + with_html <<-HTML + +
+ + +
+ + HTML + webrat_session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) + uncheck "TOS" + click_button + end + end