Fixed bug where choosing radio button in a series where a later radio button is defaulted to on resulted in the incorrect field value being submitted.

This commit is contained in:
Luke Melia 2008-09-14 21:16:39 -04:00
parent f904be9b2c
commit 7c46a6fed0
2 changed files with 16 additions and 1 deletions

View File

@ -213,7 +213,7 @@ module Webrat
def choose
other_options.each do |option|
option.unset
option.set(nil)
end
set(@element["value"] || "on")

View File

@ -77,4 +77,19 @@ describe "chooses" do
@session.should_receive(:post).with("/login", "first_option" => "on")
@session.clicks_button
end
it "should result in the value of the selected radio button being posted when a subsequent one is checked by default" do
@session.response_body = <<-EOS
<form method="post" action="/login">
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" checked="checked" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
EOS
@session.should_receive(:post).with("/login", "user" => {"gender" => "M"})
@session.chooses "Male"
@session.clicks_button
end
end