Skip to content

Commit

Permalink
Labels should only search for fields within the current scope
Browse files Browse the repository at this point in the history
  • Loading branch information
pd committed Jan 19, 2009
1 parent 14d114c commit 6529a01
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrat/core/elements/label.rb
Expand Up @@ -23,7 +23,7 @@ def field_element
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

Expand Down
21 changes: 21 additions & 0 deletions spec/public/within_spec.rb
Expand Up @@ -123,6 +123,27 @@
click_button "Add"
end
end

it "should not find fields outside of the scope" do
with_html <<-HTML
<html>
<form id="form1" action="/form1">
<label for="email">Email</label><input id="email" type="text" name="email" />
<input type="submit" value="Add" />
</form>
<form id="form2" action="/form2">
<label for="email">Email</label><input id="email" type="text" name="email" />
<input type="submit" value="Add" />
</form>
</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
Expand Down

0 comments on commit 6529a01

Please sign in to comment.