Module: Merb::Test::RequestHelper

Module | Merb::Test::RequestHelper
In: | lib/merb-core/test/helpers/mock_request_helper.rb lib/merb-core/test/helpers/request_helper.rb

### Methods

build_request check_request_for_route delete describe_input describe_request dispatch_request dispatch_to dispatch_with_basic_authentication_to fake_request get merge_controller_and_action mock_request post put requesting response_for status_code with_cookies

### Included Modules

MakeRequest

### Classes and Modules

Class Merb::Test::RequestHelper::CookieJar
Class Merb::Test::RequestHelper::FakeRequest

### Public Instance methods

build_request(params = {}, env = {})

Prepares and returns a request suitable for dispatching with dispatch_request. If you don‘t need to modify the request object before dispatching (e.g. to add cookies), you probably want to use dispatch_to instead.

#### Parameters

params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see `fake_request`), including :req or :post_body for setting the request body itself.

#### Example

      req = build_request(:id => 1)
      req.cookies['app_cookie'] = "testing"
      dispatch_request(req, MyController, :edit)

#### Notes

Does not use routes.

:api: public @deprecated

check_request_for_route(request)

Checks to see that a request is routable.

#### Parameters

request<Merb::Test::RequestHelper::FakeRequest, Merb::Request>: | The request object to inspect.

#### Raises

Merb::ControllerExceptions::BadRequest: | No matching route was found.

#### Returns

Hash: | The parameters built based on the matching route.

:api: plugin @deprecated

delete(path, params = {}, env = {}, &block)

An HTTP DELETE request that operates through the router

#### Parameters

path<String>: | The path that should go to the router as the request uri.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request).
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

:api: public @deprecated

describe_input(input)
describe_request(rack)
dispatch_request(request, controller_klass, action) {|controller if block_given?| ...}

The workhorse for the dispatch*to helpers.

#### Parameters

request<Merb::Test::RequestHelper::FakeRequest, Merb::Request>: | A request object that has been setup for testing.
controller_klass<Merb::Controller>: | The class object off the controller to dispatch the action to.
action<Symbol>: | The action to dispatch the request to.
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

#### Returns

An instance of `controller_klass` based on the parameters.

#### Notes

Does not use routes.

:api: public @deprecated

dispatch_to(controller_klass, action, params = {}, env = {}, &blk)

Dispatches an action to the given class. This bypasses the router and is suitable for unit testing of controllers.

#### Parameters

controller_klass<Controller>: | The controller class object that the action should be dispatched to.
action<Symbol>: | The action name, as a symbol.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see `fake_request`), including :req or :post_body for setting the request body itself.
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

#### Example

      dispatch_to(MyController, :create, :name => 'Homer' ) do |controller|
        controller.stub!(:current_user).and_return(@user)
      end

#### Notes

Does not use routes.

:api: public @deprecated

dispatch_with_basic_authentication_to(controller_klass, action, username, password, params = {}, env = {}, &blk)

Dispatches an action to the given class and using HTTP Basic Authentication This bypasses the router and is suitable for unit testing of controllers.

#### Parameters

controller_klass<Controller>: | The controller class object that the action should be dispatched to.
action<Symbol>: | The action name, as a symbol.
username<String>: | The username.
password<String>: | The password.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see `fake_request`), including :req or :post_body for setting the request body itself.
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

#### Example

      dispatch_with_basic_authentication_to(MyController, :create, 'Fred', 'secret', :name => 'Homer' ) do |controller|
        controller.stub!(:current_user).and_return(@user)
      end

#### Notes

Does not use routes.

:api: public @deprecated

fake_request(env = {}, opt = {})

#### Parameters

env<Hash>: | A hash of environment keys to be merged into the default list.
opt<Hash>: | A hash of options (see below).

#### Options (opt)

:post_body<String>: | The post body for the request.
:req<String>: | The request string. This will only be used if :post_body is left out.

#### Returns

FakeRequest: | A Request object that is built based on the parameters.

#### Notes

If you pass a post body, the content-type will be set to URL-encoded.

:api: public @deprecated

get(path, params = {}, env = {}, &block)

An HTTP GET request that operates through the router.

#### Parameters

path<String>: | The path that should go to the router as the request uri.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see `fake_request`).
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

:api: public @deprecated

merge_controller_and_action(controller_klass, action, params)

:api: private

mock_request(path, params = {}, env= {}, &block)

A generic request that checks the router for the controller and action. This request goes through the Merb::Router and finishes at the controller.

#### Parameters

path<String>: | The path that should go to the router as the request uri.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see `fake_request`).
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

#### Example

      request(path, { :name => 'Homer' }, { :request_method => "PUT" }) do |controller|
        controller.stub!(:current_user).and_return(@user)
      end

#### Notes

Uses Routes.

:api: plugin @deprecated

post(path, params = {}, env = {}, &block)

An HTTP POST request that operates through the router.

#### Parameters

path<String>: | The path that should go to the router as the request uri.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request).
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

:api: public @deprecated

put(path, params = {}, env = {}, &block)

An HTTP PUT request that operates through the router.

#### Parameters

path<String>: | The path that should go to the router as the request uri.
params<Hash>: | An optional hash that will end up as params in the controller instance.
env<Hash>: | An optional hash that is passed to the fake request. Any request options should go here (see fake_request).
&blk: | The controller is yielded to the block provided for actions prior to the action being dispatched.

:api: public

requesting(*args)
response_for(*args)
status_code(input)
with_cookies(*controller_classes, &blk)

Keep track of cookie values in CookieJar within the context of the block; you need to set this up for secific controllers.

#### Parameters

*controller_classes: | Controller classes to operate on in the context of the block.
&blk: | The context to operate on; optionally accepts the cookie jar as an argument.

:api: public @deprecated

[Validate]