From e1dad8ef4313abd5c2a72de43d753b5b05e225ea Mon Sep 17 00:00:00 2001 From: Zach Dennis Date: Mon, 29 Dec 2008 16:57:16 -0500 Subject: [PATCH] Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM. This caused Webrat to create multiple objects for a single DOM element since their xpath location appeared different. --- lib/webrat/core/scope.rb | 8 +------ spec/public/within_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/lib/webrat/core/scope.rb b/lib/webrat/core/scope.rb index df92c5a..db87073 100644 --- a/lib/webrat/core/scope.rb +++ b/lib/webrat/core/scope.rb @@ -291,13 +291,7 @@ module Webrat end def scoped_dom #:nodoc: - source = Webrat::XML.to_html(Webrat::XML.css_search(@scope.dom, @selector).first) - - if @session.xml_content_type? - Webrat::XML.xml_document(source) - else - Webrat::XML.html_document(source) - end + Webrat::XML.css_search(@scope.dom, @selector).first end def locate_field(field_locator, *field_types) #:nodoc: diff --git a/spec/public/within_spec.rb b/spec/public/within_spec.rb index ec8bfee..dae7e4b 100644 --- a/spec/public/within_spec.rb +++ b/spec/public/within_spec.rb @@ -59,7 +59,6 @@ describe "within" do end it "should work when the scope is inside the form" do - pending "needs bug fix" do with_html <<-HTML
@@ -77,6 +76,51 @@ describe "within" do end submit_form "form2" + end + + it "should work when the form submission occurs inside a scope" do + with_html <<-HTML + + +
+ + + + +
+ + + HTML + + webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com") + within "form[@action='/form2']" do + fill_in "Email", :with => "test@example.com" + click_button "Add" + end + end + + it "should work when there are multiple forms with the same label text" do + with_html <<-HTML + + +
+
+ + +
+
+ + +
+
+ + + HTML + + webrat_session.should_receive(:get).with("/form2", "email2" => "test@example.com") + within "form[@action='/form2']" do + fill_in "Email", :with => "test@example.com" + click_button "Add" end end -- 1.6.0.2