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) @response = mock @session.stubs(:response).returns(@response) 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_default_radio_options @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:get_via_redirect).with("/login", "user" => {"gender" => "F"}) @session.clicks_button end def test_should_send_correct_data_for_rails_style_unchecked_fields @response.stubs(:body).returns(<<-EOS) 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) EOS @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end def test_should_send_default_collection_fields @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:post_via_redirect).with("/login", "options" => ["soda", "soda", "dessert", "burger", "fries"], "response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]}) @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_send_default_selected_option_value_from_select @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:get_via_redirect).with("/login", "month" => "2") @session.clicks_button end def test_should_send_default_selected_option_inner_html_from_select_when_no_value_attribute @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:get_via_redirect).with("/login", "month" => "February") @session.clicks_button end def test_should_send_first_select_option_value_when_no_option_selected @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:get_via_redirect).with("/login", "month" => "1") @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 def test_should_send_default_empty_text_field_values @response.stubs(:body).returns(<<-EOS) EOS @session.expects(:get_via_redirect).with("/login", "user" => {"email" => ""}) @session.clicks_button end end