From 6529a016d19547962b9a22d21799d3b80718aa56 Mon Sep 17 00:00:00 2001 From: Kyle Hargraves Date: Mon, 19 Jan 2009 10:50:54 -0600 Subject: [PATCH] Labels should only search for fields within the current scope --- lib/webrat/core/elements/label.rb | 2 +- spec/public/within_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/webrat/core/elements/label.rb b/lib/webrat/core/elements/label.rb index 9e7f29b..3f8388b 100644 --- a/lib/webrat/core/elements/label.rb +++ b/lib/webrat/core/elements/label.rb @@ -23,7 +23,7 @@ module Webrat if for_id.blank? Webrat::XML.xpath_at(@element, *Field.xpath_search) else - Webrat::XML.css_search(@session.dom, "#" + for_id).first + Webrat::XML.css_search(@session.current_dom, "#" + for_id).first end end diff --git a/spec/public/within_spec.rb b/spec/public/within_spec.rb index a65cc34..a0e40ec 100644 --- a/spec/public/within_spec.rb +++ b/spec/public/within_spec.rb @@ -123,6 +123,27 @@ describe "within" do click_button "Add" end end + + it "should not find fields outside of the scope" do + with_html <<-HTML + +
+ + +
+
+ + +
+ + HTML + + webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com") + within "#form2" do + fill_in "Email", :with => "test@example.com" + click_button "Add" + end + end it "should not find buttons outside of the scope" do with_html <<-HTML