2008-04-23 14:54:07 +00:00
|
|
|
require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
|
2008-03-02 20:14:52 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
describe "selects" do
|
|
|
|
before do
|
2008-03-02 20:14:52 +00:00
|
|
|
@session = ActionController::Integration::Session.new
|
|
|
|
@session.stubs(:assert_response)
|
|
|
|
@session.stubs(:get_via_redirect)
|
|
|
|
@session.stubs(:response).returns(@response=mock)
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if option not found" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="get" action="/login">
|
|
|
|
<select name="month"><option value="1">January</option></select>
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-04-07 04:52:49 +00:00
|
|
|
|
2008-04-23 14:54:07 +00:00
|
|
|
lambda { @session.selects "February", :from => "month" }.should raise_error
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if option not found in list specified by element name" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="get" action="/login">
|
|
|
|
<select name="month"><option value="1">January</option></select>
|
|
|
|
<select name="year"><option value="2008">2008</option></select>
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-04-23 14:54:07 +00:00
|
|
|
|
|
|
|
lambda { @session.selects "February", :from => "year" }.should raise_error
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should fail if specified list not found" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="get" action="/login">
|
|
|
|
<select name="month"><option value="1">January</option></select>
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-04-23 14:54:07 +00:00
|
|
|
|
|
|
|
lambda { @session.selects "February", :from => "year" }.should raise_error
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should send value from option" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="month"><option value="1">January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", "month" => "1")
|
2008-04-07 04:52:49 +00:00
|
|
|
@session.selects "January", :from => "month"
|
2008-03-02 20:14:52 +00:00
|
|
|
@session.clicks_button
|
|
|
|
end
|
2008-04-13 23:02:35 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work with empty select lists" do
|
2008-04-13 23:02:35 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="month"></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", 'month' => '')
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
2008-03-02 20:14:52 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should work without specifying the field name or label" do
|
2008-04-08 02:26:24 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="month"><option value="1">January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", "month" => "1")
|
|
|
|
@session.selects "January"
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should send value from option in list specified by name" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="start_month"><option value="s1">January</option></select>
|
|
|
|
<select name="end_month"><option value="e1">January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-03-12 06:04:41 +00:00
|
|
|
@session.expects(:post_via_redirect).with("/login", "start_month" => "s1", "end_month" => "e1")
|
2008-03-02 20:14:52 +00:00
|
|
|
@session.selects "January", :from => "end_month"
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should send value from option in list specified by label" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="start_month">Start Month</label>
|
|
|
|
<select id="start_month" name="start_month"><option value="s1">January</option></select>
|
|
|
|
<label for="end_month">End Month</label>
|
|
|
|
<select id="end_month" name="end_month"><option value="e1">January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
2008-03-12 06:04:41 +00:00
|
|
|
@session.expects(:post_via_redirect).with("/login", "start_month" => "s1", "end_month" => "e1")
|
2008-03-02 20:14:52 +00:00
|
|
|
@session.selects "January", :from => "End Month"
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should use option text if no value" do
|
2008-03-02 20:14:52 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="month"><option>January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", "month" => "January")
|
2008-04-07 04:52:49 +00:00
|
|
|
@session.selects "January", :from => "month"
|
2008-03-02 20:14:52 +00:00
|
|
|
@session.clicks_button
|
|
|
|
end
|
2008-04-12 21:22:20 +00:00
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should find option by regexp" do
|
2008-04-12 21:22:20 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<select name="month"><option>January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", "month" => "January")
|
|
|
|
@session.selects(/jan/i)
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
|
|
|
|
2008-04-27 16:45:01 +00:00
|
|
|
it "should find option by regexp in list specified by label" do
|
2008-04-12 21:22:20 +00:00
|
|
|
@response.stubs(:body).returns(<<-EOS)
|
|
|
|
<form method="post" action="/login">
|
|
|
|
<label for="start_month">Start Month</label>
|
|
|
|
<select id="start_month" name="start_month"><option value="s1">January</option></select>
|
|
|
|
<label for="end_month">End Month</label>
|
|
|
|
<select id="end_month" name="end_month"><option value="e1">January</option></select>
|
|
|
|
<input type="submit" />
|
|
|
|
</form>
|
|
|
|
EOS
|
|
|
|
@session.expects(:post_via_redirect).with("/login", "start_month" => "s1", "end_month" => "e1")
|
|
|
|
@session.selects(/jan/i, :from => "End Month")
|
|
|
|
@session.clicks_button
|
|
|
|
end
|
2008-03-02 20:14:52 +00:00
|
|
|
end
|