value of checbkox/radio defaults to "on" when not specified

This commit is contained in:
Thomas Walpole 2013-10-28 15:58:04 -07:00
parent 33a699be13
commit 483f261c3c
3 changed files with 16 additions and 1 deletions

View File

@ -82,6 +82,8 @@ module Capybara
option = native.xpath(".//option[@selected='selected']").first || native.xpath(".//option").first
option[:value] || option.content if option
end
elsif tag_name == 'input' && %w(radio checkbox).include?(native[:type])
native[:value] || 'on'
else
native[:value]
end

View File

@ -28,7 +28,10 @@ class Capybara::RackTest::Form < Capybara::RackTest::Node
case field.name
when 'input'
if %w(radio checkbox).include? field['type']
merge_param!(params, field['name'].to_s, field['value'].to_s) if field['checked']
if field['checked']
node=Capybara::RackTest::Node.new(self.driver, field)
merge_param!(params, field['name'].to_s, node.value.to_s)
end
elsif %w(submit image).include? field['type']
# TO DO identify the click button here (in document order, rather
# than leaving until the end of the params)

View File

@ -67,6 +67,16 @@ Capybara::SpecHelper.spec "node" do
@session.find('//textarea[1]').set("some <em>html</em> here")
@session.find('//textarea[1]').value.should == "some <em>html</em> here"
end
it "defaults to 'on' for checkbox" do
@session.visit('/form')
@session.find('//input[@id="valueless_checkbox"]').value.should == 'on'
end
it "defaults to 'on' for radio buttons" do
@session.visit('/form')
@session.find('//input[@id="valueless_radio"]').value.should == 'on'
end
end
describe "#set" do