2008-11-14 04:26:19 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
|
|
|
|
|
|
describe "select_time" do
|
|
|
|
it "should send the values for each individual time component" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-14 04:26:19 +00:00
|
|
|
<form action="/appointments" method="post">
|
|
|
|
<label for="appointment_time">Time</label><br />
|
|
|
|
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
|
|
|
<option value="09">09</option>
|
|
|
|
</select>
|
|
|
|
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
|
|
|
<option value="30">30</option>
|
|
|
|
</select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/appointments",
|
2008-11-14 04:26:19 +00:00
|
|
|
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
|
2008-11-23 19:02:51 +00:00
|
|
|
select_time "9:30AM", :from => "Time"
|
2008-11-23 05:22:49 +00:00
|
|
|
click_button
|
2008-11-14 04:26:19 +00:00
|
|
|
end
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-14 04:26:19 +00:00
|
|
|
it "should accept a time object" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-14 04:26:19 +00:00
|
|
|
<form action="/appointments" method="post">
|
|
|
|
<label for="appointment_time">Time</label><br />
|
|
|
|
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
|
|
|
<option value="09">09</option>
|
|
|
|
</select>
|
|
|
|
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
|
|
|
<option value="30">30</option>
|
|
|
|
</select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/appointments",
|
2008-11-14 04:26:19 +00:00
|
|
|
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
|
2008-11-23 05:22:49 +00:00
|
|
|
select_time Time.parse("9:30AM"), :from => "Time"
|
|
|
|
click_button
|
2008-11-14 04:26:19 +00:00
|
|
|
end
|
2009-04-14 21:09:46 +00:00
|
|
|
|
|
|
|
it "should work when the label ends in a non word character" do
|
|
|
|
with_html <<-HTML
|
|
|
|
<html>
|
|
|
|
<form action="/appointments" method="post">
|
|
|
|
<label for="appointment_time">Time #</label><br />
|
|
|
|
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
|
|
|
<option value="09">09</option>
|
|
|
|
</select>
|
|
|
|
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
|
|
|
<option value="30">30</option>
|
|
|
|
</select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
</html>
|
|
|
|
HTML
|
2009-05-11 20:51:42 +00:00
|
|
|
webrat_session.should_receive(:post).with("/appointments",
|
2009-04-14 21:09:46 +00:00
|
|
|
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
|
|
|
|
select_time "9:30AM", :from => "Time #"
|
|
|
|
click_button
|
|
|
|
end
|
2008-11-14 04:26:19 +00:00
|
|
|
|
|
|
|
it "should work when no label is specified" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-14 04:26:19 +00:00
|
|
|
<form action="/appointments" method="post">
|
|
|
|
<select id="appointment_time_4i" name="appointment[time(4i)]">
|
|
|
|
<option value="09">09</option>
|
|
|
|
</select>
|
|
|
|
: <select id="appointment_time_5i" name="appointment[time(5i)]">
|
|
|
|
<option value="30">30</option>
|
|
|
|
</select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-05-11 20:48:28 +00:00
|
|
|
webrat_session.should_receive(:post).with("/appointments",
|
2008-11-14 04:26:19 +00:00
|
|
|
"appointment" => {"time(4i)" => "09", "time(5i)" => "30"})
|
2008-11-23 05:22:49 +00:00
|
|
|
select_time "9:30"
|
|
|
|
click_button
|
2008-11-14 04:26:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should fail if the specified label is not found" do
|
2008-11-23 05:22:49 +00:00
|
|
|
with_html <<-HTML
|
2008-11-28 05:34:35 +00:00
|
|
|
<html>
|
2008-11-14 04:26:19 +00:00
|
|
|
<form method="post" action="/appointments">
|
|
|
|
<select name="month"><option>January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
2008-11-28 05:34:35 +00:00
|
|
|
</html>
|
2008-11-23 05:22:49 +00:00
|
|
|
HTML
|
2009-04-08 00:30:12 +00:00
|
|
|
|
2008-11-23 19:08:34 +00:00
|
|
|
lambda { select_time "9:30", :from => "Time" }.should raise_error(Webrat::NotFoundError)
|
2008-11-14 04:26:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|