TestProcessor is a class that exercises a Rails controller action.

TestProcessor is heavily based on ActionPack’s lib/action_controller/test_process.rb

The original can be found at: dev.rubyonrails.org/browser/trunk/actionpack/lib/action_controller/test_process.rb

The methods process and build_request_uri are copyright © 2004 David Heinemeier Hansson and are used under the MIT License. All original code is subject to the LICENSE file included with Action Profiler.

Methods
Public Class methods
new(action, method, params = nil, session = nil, flash = nil)

Creates a new TestProcessor that will profile action with method. params, session and flash are hashes for use in processing the request.

action is a String with the format "GamesController#index".

method is one of the HTTP request methods, get, post, etc.

    # File lib/action_profiler/test_processor.rb, line 71
71:   def initialize(action, method, params = nil, session = nil, flash = nil)
72:     unless action =~ /^([:\w]+Controller)#(\w+)$/ then
73:       raise ArgumentError, "invalid action name" 
74:     end
75: 
76:     @controller_name = $1
77:     @action_name = $2
78:     @method = method.downcase
79: 
80:     @params = params
81:     @session = session
82:     @flash = flash
83: 
84:     begin
85:       controller_klass = Object.path2class @controller_name
86:     rescue NameError
87:       raise ArgumentError, "can't find controller #{@controller_name}"
88:     end
89: 
90:     @controller = controller_klass.new
91:     @request = ActionController::TestRequest.new
92:     @response = ActionController::TestResponse.new
93:     ActionMailer::Base.delivery_method = :test
94:     ActionMailer::Base.deliveries = []
95:   end
Public Instance methods
process()

Runs this action.

     # File lib/action_profiler/test_processor.rb, line 100
100:   def process
101:     @request.recycle!
102: 
103:     @html_document = nil # Why? Who knows!
104:     @request.env['REQUEST_METHOD'] = @method
105:     @request.action = @action_name
106: 
107:     @request.assign_parameters(@controller.class.controller_path, @action_name,
108:                                @params)
109: 
110:     @request.session = ActionController::TestSession.new @session
111:     @request.session['flash'] = ActionController::Flash::FlashHash.new
112:     @request.session['flash'].update @flash
113: 
114:     build_request_uri
115:     @controller.process @request, @response
116:   end
Private Instance methods
build_request_uri()
     # File lib/action_profiler/test_processor.rb, line 120
120:   def build_request_uri
121:     return if @request.env['REQUEST_URI']
122:     options = @controller.send :rewrite_options, @params
123:     options.update :only_path => true, :action => @action_name
124: 
125:     url = ActionController::UrlRewriter.new @request, @params
126:     @request.set_REQUEST_URI url.rewrite(options)
127:   end