radio buttons can have multiple labels
This commit is contained in:
parent
17f4dba965
commit
a9430aa2ce
@ -25,8 +25,8 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def label_text
|
def label_text
|
||||||
return nil unless label
|
return nil if labels.empty?
|
||||||
label.text
|
labels.first.text
|
||||||
end
|
end
|
||||||
|
|
||||||
def matches_id?(id)
|
def matches_id?(id)
|
||||||
@ -38,8 +38,8 @@ module Webrat
|
|||||||
end
|
end
|
||||||
|
|
||||||
def matches_label?(label_text)
|
def matches_label?(label_text)
|
||||||
return false unless label
|
return false if labels.empty?
|
||||||
label.matches_text?(label_text)
|
labels.any? { |label| label.matches_text?(label_text) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
@ -65,25 +65,29 @@ module Webrat
|
|||||||
@element["name"]
|
@element["name"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def label
|
def labels
|
||||||
return nil if label_element.nil?
|
return nil if label_elements.empty?
|
||||||
@label ||= Label.new(self, label_element)
|
@labels ||= label_elements.map { |element| Label.new(self, element) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def label_element
|
def label_elements
|
||||||
@label_element ||= begin
|
return @label_elements unless @label_elements.nil?
|
||||||
|
@label_elements = []
|
||||||
|
|
||||||
parent = @element.parent
|
parent = @element.parent
|
||||||
while parent.respond_to?(:parent)
|
while parent.respond_to?(:parent)
|
||||||
return parent if parent.name == "label"
|
if parent.name == 'label'
|
||||||
|
@label_elements.push parent
|
||||||
|
break
|
||||||
|
end
|
||||||
parent = parent.parent
|
parent = parent.parent
|
||||||
end
|
end
|
||||||
|
|
||||||
if id.blank?
|
unless id.blank?
|
||||||
nil
|
@label_elements += @form.element / "label[@for=#{id}]"
|
||||||
else
|
|
||||||
@form.element.at("label[@for=#{id}]")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@label_elements
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_value
|
def default_value
|
||||||
|
@ -39,6 +39,23 @@ describe "chooses" do
|
|||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should use any of the button's labels" do
|
||||||
|
@session.response_body = <<-EOS
|
||||||
|
<form method="get" action="/login">
|
||||||
|
<label for="user_gender_male"><img src="male.jpg" /></label>
|
||||||
|
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
|
||||||
|
<label for="user_gender_male">Male</label>
|
||||||
|
<label for="user_gender_female"><img src="female.jpg" /></label>
|
||||||
|
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
|
||||||
|
<label for="user_gender_female">Female</label>
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
EOS
|
||||||
|
@session.expects(:get).with("/login", "user" => {"gender" => "M"})
|
||||||
|
@session.chooses "Male"
|
||||||
|
@session.clicks_button
|
||||||
|
end
|
||||||
|
|
||||||
it "should only submit last chosen value" do
|
it "should only submit last chosen value" do
|
||||||
@session.response_body = <<-EOS
|
@session.response_body = <<-EOS
|
||||||
<form method="get" action="/login">
|
<form method="get" action="/login">
|
||||||
|
Loading…
Reference in New Issue
Block a user