Skip to content

Commit

Permalink
Fixed bug where choosing radio button in a series where a later radio…
Browse files Browse the repository at this point in the history
… button is defaulted to on resulted in the incorrect field value being submitted.
  • Loading branch information
lukemelia committed Sep 15, 2008
1 parent f904be9 commit 7c46a6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webrat/core/field.rb
Expand Up @@ -213,7 +213,7 @@ def to_param

def choose
other_options.each do |option|
option.unset
option.set(nil)
end

set(@element["value"] || "on")
Expand Down
15 changes: 15 additions & 0 deletions spec/api/chooses_spec.rb
Expand Up @@ -77,4 +77,19 @@
@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

0 comments on commit 7c46a6f

Please sign in to comment.