webrat/test/checks_test.rb

131 lines
3.8 KiB
Ruby
Raw Normal View History

2008-03-02 20:14:52 +00:00
require File.dirname(__FILE__) + "/helper"
class ChecksTest < Test::Unit::TestCase
def setup
2008-04-18 12:37:03 +00:00
@session = test_session
2008-03-02 20:14:52 +00:00
@session.stubs(:assert_response)
@session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock)
end
def test_should_fail_if_no_checkbox_found
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
</form>
EOS
2008-04-07 04:52:49 +00:00
assert_raises RuntimeError do
@session.checks "remember_me"
end
2008-03-02 20:14:52 +00:00
end
def test_should_fail_if_input_is_not_a_checkbox
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
EOS
2008-04-07 04:52:49 +00:00
assert_raises RuntimeError do
@session.checks "remember_me"
end
2008-03-02 20:14:52 +00:00
end
def test_should_check_rails_style_checkboxes
@response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
EOS
@session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"})
@session.checks "TOS"
@session.clicks_button
end
def test_should_result_in_the_value_on_being_posted_if_not_specified
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="checkbox" name="remember_me" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", "remember_me" => "on")
@session.checks "remember_me"
@session.clicks_button
end
def test_should_result_in_a_custom_value_being_posted
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", "remember_me" => "yes")
@session.checks "remember_me"
@session.clicks_button
end
end
class UnchecksTest < Test::Unit::TestCase
def setup
2008-04-18 12:37:03 +00:00
@session = test_session
2008-03-02 20:14:52 +00:00
@session.stubs(:assert_response)
@session.stubs(:get_via_redirect)
@session.stubs(:response).returns(@response=mock)
end
def test_should_fail_if_no_checkbox_found
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
</form>
EOS
2008-04-07 04:52:49 +00:00
assert_raises RuntimeError do
@session.unchecks "remember_me"
end
2008-03-02 20:14:52 +00:00
end
def test_should_fail_if_input_is_not_a_checkbox
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="text" name="remember_me" />
</form>
EOS
2008-04-07 04:52:49 +00:00
assert_raises RuntimeError do
@session.unchecks "remember_me"
end
2008-03-02 20:14:52 +00:00
end
def test_should_uncheck_rails_style_checkboxes
@response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login">
<input id="user_tos" name="user[tos]" type="checkbox" value="1" checked="checked" />
<input name="user[tos]" type="hidden" value="0" />
<label for="user_tos">TOS</label>
<input type="submit" />
</form>
EOS
@session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "0"})
2008-04-07 04:52:49 +00:00
@session.checks "TOS"
2008-03-02 20:14:52 +00:00
@session.unchecks "TOS"
@session.clicks_button
end
def test_should_result_in_value_not_being_posted
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="checkbox" name="remember_me" value="yes" checked="checked" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", {})
@session.unchecks "remember_me"
@session.clicks_button
end
end