Module: ActionController::TestCase::Behavior
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActionDispatch::TestProcess
- Included in:
- ActionController::TestCase
- Defined in:
- lib/action_controller/test_case.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#delete(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating DELETE HTTP method and set/volley the response.
-
#get(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating GET HTTP method and set/volley the response.
-
#head(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating HEAD HTTP method and set/volley the response.
-
#post(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating POST HTTP method and set/volley the response.
- #process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') ⇒ Object
-
#put(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating PUT HTTP method and set/volley the response.
-
#rescue_action_in_public! ⇒ Object
Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local.
- #setup_controller_request_and_response ⇒ Object
- #xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) ⇒ Object (also: #xhr)
Methods included from ActionDispatch::TestProcess
#assigns, #cookies, #fixture_file_upload, #flash, #redirect_to_url, #session
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
306 307 308 |
# File 'lib/action_controller/test_case.rb', line 306 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
306 307 308 |
# File 'lib/action_controller/test_case.rb', line 306 def response @response end |
Instance Method Details
#delete(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating DELETE HTTP method and set/volley the response
357 358 359 |
# File 'lib/action_controller/test_case.rb', line 357 def delete(action, parameters = nil, session = nil, flash = nil) process(action, parameters, session, flash, "DELETE") end |
#get(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating GET HTTP method and set/volley the response
342 343 344 |
# File 'lib/action_controller/test_case.rb', line 342 def get(action, parameters = nil, session = nil, flash = nil) process(action, parameters, session, flash, "GET") end |
#head(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating HEAD HTTP method and set/volley the response
362 363 364 |
# File 'lib/action_controller/test_case.rb', line 362 def head(action, parameters = nil, session = nil, flash = nil) process(action, parameters, session, flash, "HEAD") end |
#post(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating POST HTTP method and set/volley the response
347 348 349 |
# File 'lib/action_controller/test_case.rb', line 347 def post(action, parameters = nil, session = nil, flash = nil) process(action, parameters, session, flash, "POST") end |
#process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/action_controller/test_case.rb', line 376 def process(action, parameters = nil, session = nil, flash = nil, http_method = 'GET') # Sanity check for required instance variables so we can give an # understandable error message. %w(@routes @controller @request @response).each do |iv_name| if !(instance_variable_names.include?(iv_name) || instance_variable_names.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? raise "#{iv_name} is nil: make sure you set it in your test's setup method." end end @request.recycle! @response.recycle! @controller.response_body = nil @controller.formats = nil @controller.params = nil @html_document = nil @request.env['REQUEST_METHOD'] = http_method parameters ||= {} @request.assign_parameters(@routes, @controller.class.name.underscore.sub(/_controller$/, ''), action.to_s, parameters) @request.session = ActionController::TestSession.new(session) unless session.nil? @request.session["flash"] = @request.flash.update(flash || {}) @request.session["flash"].sweep @controller.request = @request @controller.params.merge!(parameters) build_request_uri(action, parameters) Base.class_eval { include Testing } @controller.process_with_new_base_test(@request, @response) @request.session.delete('flash') if @request.session['flash'].blank? @response end |
#put(action, parameters = nil, session = nil, flash = nil) ⇒ Object
Executes a request simulating PUT HTTP method and set/volley the response
352 353 354 |
# File 'lib/action_controller/test_case.rb', line 352 def put(action, parameters = nil, session = nil, flash = nil) process(action, parameters, session, flash, "PUT") end |
#rescue_action_in_public! ⇒ Object
Cause the action to be rescued according to the regular rules for rescue_action when the visitor is not local
427 428 429 |
# File 'lib/action_controller/test_case.rb', line 427 def rescue_action_in_public! @request.remote_addr = '208.77.188.166' # example.com end |
#setup_controller_request_and_response ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/action_controller/test_case.rb', line 410 def setup_controller_request_and_response @request = TestRequest.new @response = TestResponse.new if klass = self.class.controller_class @controller ||= klass.new rescue nil end @request.env.delete('PATH_INFO') if @controller @controller.request = @request @controller.params = {} end end |
#xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) ⇒ Object Also known as: xhr
366 367 368 369 370 371 372 373 |
# File 'lib/action_controller/test_case.rb', line 366 def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' @request.env['HTTP_ACCEPT'] ||= [Mime::JS, Mime::HTML, Mime::XML, 'text/xml', Mime::ALL].join(', ') __send__(request_method, action, parameters, session, flash).tap do @request.env.delete 'HTTP_X_REQUESTED_WITH' @request.env.delete 'HTTP_ACCEPT' end end |