Clicking Links in UnitTests

Using click /change/i is a good way of testing you links/methods, since it will assure your views render the valid link and you do not have to repeat the link parameters as in get :edit, :id=>3

  1. get form_test_helper with
    script/plugin install
  2. patch vendor/plugins/form_test_helper/lib/form_test_helper.rb
    -  if self["onclick"] && self["onclick"] =~ /'_method'.*'value', '(\w+)'/
    -    $1.to_sym
    +  if self["onclick"] && self["onclick"] =~ /\.method = '(.*)'/
    +    $1.downcase.to_sym
  3. insert helper to test/test_helper.rb
      def click(text)
  4. click click click clickaround!
      def test_should_not_upload_from_ftp
        login_as :aaron
        assert_invalid_upload do
          `cp -f test/fixtures/videos/ #{ftp_accounts(:aaron).dir}/wrong_name.flv`
          click /upload.*ftp/i
          assert_response :redirect
          assert flash[:alert]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s