require File.dirname(__FILE__) + "/helper" class ClicksButtonTest < Test::Unit::TestCase def setup @session = ActionController::Integration::Session.new @session.stubs(:assert_response) @session.stubs(:get_via_redirect) @session.stubs(:response).returns(@response=mock) end def test_should_fail_if_no_buttons @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:flunk) @session.clicks_button end def test_should_fail_if_input_is_not_a_submit_button @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:flunk) @session.clicks_button end def test_should_default_to_get_method @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect) @session.clicks_button end def test_should_assert_valid_response @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:assert_response).with(:success) @session.clicks_button end def test_should_default_to_current_url @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:current_url).returns("/current") @session.expects(:get_via_redirect).with("/current", {}) @session.clicks_button end def test_should_submit_the_first_form_by_default @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/form1", {}) @session.clicks_button end def test_should_submit_the_form_with_the_specified_button @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/form2", {}) @session.clicks_button "Form2" end def test_should_use_action_from_form @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/login", {}) @session.clicks_button end def test_should_use_method_from_form @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect) @session.clicks_button end def test_should_send_button_as_param_if_it_has_a_name @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "login" => "Login") @session.clicks_button("Login") end def test_should_not_send_button_as_param_if_it_has_no_name @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", {}) @session.clicks_button("Login") end def test_should_send_default_hidden_field_values @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end def test_should_send_default_text_field_values @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end def test_should_send_default_checked_fields @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end def test_should_send_correct_data_for_rails_style_unchecked_fields @response.stubs(:body).returns(<<-EOS)
TOS
EOS @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "0"}) @session.clicks_button end def test_should_send_correct_data_for_rails_style_checked_fields @response.stubs(:body).returns(<<-EOS)
TOS
EOS @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end def test_should_not_send_default_unchecked_fields @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:get_via_redirect).with("/login", {}) @session.clicks_button end def test_should_send_default_textarea_values @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/posts", "post" => {"body" => "Post body here!"}) @session.clicks_button end def test_should_handle_nested_properties @response.stubs(:body).returns(<<-EOS)
EOS @session.expects(:post_via_redirect).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) @session.clicks_button end end