Methods
Included Modules
Public Class methods
included(base)
     # File actionpack/lib/action_controller/test_process.rb, line 395
395:     def self.included(base)
396:       # Executes a request simulating GET HTTP method and set/volley the response
397:       def get(action, parameters = nil, session = nil, flash = nil)
398:         process(action, parameters, session, flash, "GET")
399:       end
400: 
401:       # Executes a request simulating POST HTTP method and set/volley the response
402:       def post(action, parameters = nil, session = nil, flash = nil)
403:         process(action, parameters, session, flash, "POST")
404:       end
405: 
406:       # Executes a request simulating PUT HTTP method and set/volley the response
407:       def put(action, parameters = nil, session = nil, flash = nil)
408:         process(action, parameters, session, flash, "PUT")
409:       end
410: 
411:       # Executes a request simulating DELETE HTTP method and set/volley the response
412:       def delete(action, parameters = nil, session = nil, flash = nil)
413:         process(action, parameters, session, flash, "DELETE")
414:       end
415: 
416:       # Executes a request simulating HEAD HTTP method and set/volley the response
417:       def head(action, parameters = nil, session = nil, flash = nil)
418:         process(action, parameters, session, flash, "HEAD")
419:       end
420:     end
Public Instance methods
assigns(key = nil)
     # File actionpack/lib/action_controller/test_process.rb, line 460
460:     def assigns(key = nil)
461:       if key.nil?
462:         @response.template.assigns
463:       else
464:         @response.template.assigns[key.to_s]
465:       end
466:     end
build_request_uri(action, parameters)
     # File actionpack/lib/action_controller/test_process.rb, line 484
484:     def build_request_uri(action, parameters)
485:       unless @request.env['REQUEST_URI']
486:         options = @controller.__send__(:rewrite_options, parameters)
487:         options.update(:only_path => true, :action => action)
488: 
489:         url = ActionController::UrlRewriter.new(@request, parameters)
490:         @request.set_REQUEST_URI(url.rewrite(options))
491:       end
492:     end
cookies()
     # File actionpack/lib/action_controller/test_process.rb, line 476
476:     def cookies
477:       @response.cookies
478:     end
delete(action, parameters = nil, session = nil, flash = nil)

Executes a request simulating DELETE HTTP method and set/volley the response

     # File actionpack/lib/action_controller/test_process.rb, line 412
412:       def delete(action, parameters = nil, session = nil, flash = nil)
413:         process(action, parameters, session, flash, "DELETE")
414:       end
find_all_tag(conditions)
     # File actionpack/lib/action_controller/test_process.rb, line 503
503:     def find_all_tag(conditions)
504:       html_document.find_all(conditions)
505:     end
find_tag(conditions)
     # File actionpack/lib/action_controller/test_process.rb, line 499
499:     def find_tag(conditions)
500:       html_document.find(conditions)
501:     end
fixture_file_upload(path, mime_type = nil, binary = false)

Shortcut for ActionController::TestUploadedFile.new(ActionController::TestCase.fixture_path + path, type):

  post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png')

To upload binary files on Windows, pass :binary as the last parameter. This will not affect other platforms:

  post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png', :binary)
     # File actionpack/lib/action_controller/test_process.rb, line 523
523:     def fixture_file_upload(path, mime_type = nil, binary = false)
524:       fixture_path = ActionController::TestCase.send(:fixture_path) if ActionController::TestCase.respond_to?(:fixture_path)
525:       ActionController::TestUploadedFile.new("#{fixture_path}#{path}", mime_type, binary)
526:     end
flash()
     # File actionpack/lib/action_controller/test_process.rb, line 472
472:     def flash
473:       @response.flash
474:     end
get(action, parameters = nil, session = nil, flash = nil)

Executes a request simulating GET HTTP method and set/volley the response

     # File actionpack/lib/action_controller/test_process.rb, line 397
397:       def get(action, parameters = nil, session = nil, flash = nil)
398:         process(action, parameters, session, flash, "GET")
399:       end
head(action, parameters = nil, session = nil, flash = nil)

Executes a request simulating HEAD HTTP method and set/volley the response

     # File actionpack/lib/action_controller/test_process.rb, line 417
417:       def head(action, parameters = nil, session = nil, flash = nil)
418:         process(action, parameters, session, flash, "HEAD")
419:       end
html_document()
     # File actionpack/lib/action_controller/test_process.rb, line 494
494:     def html_document
495:       xml = @response.content_type =~ /xml$/
496:       @html_document ||= HTML::Document.new(@response.body, false, xml)
497:     end
method_missing(selector, *args, &block)
     # File actionpack/lib/action_controller/test_process.rb, line 507
507:     def method_missing(selector, *args, &block)
508:       if @controller && ActionController::Routing::Routes.named_routes.helpers.include?(selector)
509:         @controller.send(selector, *args, &block)
510:       else
511:         super
512:       end
513:     end
post(action, parameters = nil, session = nil, flash = nil)

Executes a request simulating POST HTTP method and set/volley the response

     # File actionpack/lib/action_controller/test_process.rb, line 402
402:       def post(action, parameters = nil, session = nil, flash = nil)
403:         process(action, parameters, session, flash, "POST")
404:       end
process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
     # File actionpack/lib/action_controller/test_process.rb, line 422
422:     def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET')
423:       # Sanity check for required instance variables so we can give an
424:       # understandable error message.
425:       %w(@controller @request @response).each do |iv_name|
426:         if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil?
427:           raise "#{iv_name} is nil: make sure you set it in your test's setup method."
428:         end
429:       end
430: 
431:       @request.recycle!
432:       @response.recycle!
433: 
434:       @html_document = nil
435:       @request.env['REQUEST_METHOD'] = http_method
436: 
437:       @request.action = action.to_s
438: 
439:       parameters ||= {}
440:       @request.assign_parameters(@controller.class.controller_path, action.to_s, parameters)
441: 
442:       @request.session = ActionController::TestSession.new(session) unless session.nil?
443:       @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
444:       build_request_uri(action, parameters)
445: 
446:       Base.class_eval { include ProcessWithTest } unless Base < ProcessWithTest
447:       @controller.process_with_test(@request, @response)
448:     end
put(action, parameters = nil, session = nil, flash = nil)

Executes a request simulating PUT HTTP method and set/volley the response

     # File actionpack/lib/action_controller/test_process.rb, line 407
407:       def put(action, parameters = nil, session = nil, flash = nil)
408:         process(action, parameters, session, flash, "PUT")
409:       end
redirect_to_url()
     # File actionpack/lib/action_controller/test_process.rb, line 480
480:     def redirect_to_url
481:       @response.redirect_url
482:     end
session()
     # File actionpack/lib/action_controller/test_process.rb, line 468
468:     def session
469:       @request.session
470:     end
with_routing() {|temporary_routes| ...}

A helper to make it easier to test different route configurations. This method temporarily replaces ActionController::Routing::Routes with a new RouteSet instance.

The new instance is yielded to the passed block. Typically the block will create some routes using map.draw { map.connect … }:

  with_routing do |set|
    set.draw do |map|
      map.connect ':controller/:action/:id'
        assert_equal(
          ['/content/10/show', {}],
          map.generate(:controller => 'content', :id => 10, :action => 'show')
      end
    end
  end
     # File actionpack/lib/action_controller/test_process.rb, line 545
545:     def with_routing
546:       real_routes = ActionController::Routing::Routes
547:       ActionController::Routing.module_eval { remove_const :Routes }
548: 
549:       temporary_routes = ActionController::Routing::RouteSet.new
550:       ActionController::Routing.module_eval { const_set :Routes, temporary_routes }
551: 
552:       yield temporary_routes
553:     ensure
554:       if ActionController::Routing.const_defined? :Routes
555:         ActionController::Routing.module_eval { remove_const :Routes }
556:       end
557:       ActionController::Routing.const_set(:Routes, real_routes) if real_routes
558:     end
xhr(request_method, action, parameters = nil, session = nil, flash = nil)

Alias for xml_http_request

xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
This method is also aliased as xhr
     # File actionpack/lib/action_controller/test_process.rb, line 450
450:     def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
451:       @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
452:       @request.env['HTTP_ACCEPT'] =  [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ')
453:       __send__(request_method, action, parameters, session, flash).tap do
454:         @request.env.delete 'HTTP_X_REQUESTED_WITH'
455:         @request.env.delete 'HTTP_ACCEPT'
456:       end
457:     end