Skip to content

Commit

Permalink
field_labeled() should disregard labels without matching fields
Browse files Browse the repository at this point in the history
  • Loading branch information
pd committed Jan 18, 2009
1 parent cbd323a commit 2b38b78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions History.txt
Expand Up @@ -68,6 +68,7 @@

* Bug fixes

* field_labeled should disregard labels without matching fields (Kyle Hargraves)
* Fixed bug where Scope was creating a new DOM rather than re-using the existing DOM.
[#105] (Zach Dennis)
* Support Rails > v2.2 by using ActionController::RequestParser for param parsing [#107]
Expand Down
4 changes: 2 additions & 2 deletions lib/webrat/core/locators/field_labeled_locator.rb
Expand Up @@ -7,7 +7,7 @@ module Locators
class FieldLabeledLocator < Locator # :nodoc:

def locate
matching_labels.any? && matching_labels.first.field
matching_labels.any? && matching_labels.detect_mapped { |label| label.field }
end

def matching_labels
Expand Down Expand Up @@ -53,4 +53,4 @@ def field_labeled(label, *field_types)
end

end
end
end
15 changes: 15 additions & 0 deletions spec/public/locators/field_labeled_spec.rb
Expand Up @@ -138,5 +138,20 @@ def match_id(id)
with_an_id_of "element_42", :for => "A label with a link on it's own line"
should_raise_error_matching /Could not find .* "Other Label"/, :for => "Other Label"
end

describe "finding a field when labels without fields also match" do
using_this_html <<-HTML
<html>
<label>The Label</label>
<form>
<label for="element_42">The Label</label>
<input type="text" id="element_42">
</form>
</html>
HTML

should_return_a Webrat::TextField, :for => "The Label"
with_an_id_of "element_42", :for => "The Label"
end

end

0 comments on commit 2b38b78

Please sign in to comment.