2008-05-12 03:58:20 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2008-04-07 17:48:45 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
describe "chooses" do
|
|
|
|
before do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session = Webrat::TestSession.new
|
2008-04-07 17:48:45 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if no radio buttons found" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
lambda { @session.chooses "first option" }.should raise_error
|
2008-04-07 17:48:45 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if input is not a radio button" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input type="text" name="first_option" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
lambda { @session.chooses "first_option" }.should raise_error
|
2008-04-07 17:48:45 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should check rails style radio buttons" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="get" 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" />
|
|
|
|
<label for="user_gender_female">Female</label>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-07-25 23:11:56 +00:00
|
|
|
@session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
|
2008-07-08 17:31:44 +00:00
|
|
|
@session.chooses "Male"
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should only submit last chosen value" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="get" 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" />
|
|
|
|
<label for="user_gender_female">Female</label>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-07-25 23:11:56 +00:00
|
|
|
@session.should_receive(:get).with("/login", "user" => {"gender" => "M"})
|
2008-04-07 17:48:45 +00:00
|
|
|
@session.chooses "Female"
|
|
|
|
@session.chooses "Male"
|
|
|
|
@session.clicks_button
|
2008-10-02 00:22:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should fail if the radio button is disabled" do
|
|
|
|
@session.response_body = <<-EOS
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<input type="radio" name="first_option" disabled="disabled" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
|
|
|
|
lambda { @session.chooses "first_option" }.should raise_error
|
|
|
|
end
|
2008-04-07 17:48:45 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should result in the value on being posted if not specified" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input type="radio" name="first_option" />
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-07-25 23:11:56 +00:00
|
|
|
@session.should_receive(:post).with("/login", "first_option" => "on")
|
2008-04-07 17:48:45 +00:00
|
|
|
@session.chooses "first_option"
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should result in the value on being posted if not specified and checked by default" do
|
2008-05-12 03:58:20 +00:00
|
|
|
@session.response_body = <<-EOS
|
2008-04-07 17:48:45 +00:00
|
|
|
<form method="post" action="/login">
|
|
|
|
<input type="radio" name="first_option" checked="checked"/>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-07-25 23:11:56 +00:00
|
|
|
@session.should_receive(:post).with("/login", "first_option" => "on")
|
2008-04-07 17:48:45 +00:00
|
|
|
@session.clicks_button
|
|
|
|
end
|
2008-09-15 01:16:39 +00:00
|
|
|
|
|
|
|
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
|
2008-04-27 16:45:01 +00:00
|
|
|
end
|