Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 8b99df826c3b6cf56a1caaae5f931d50 > files > 163

ruby-actionpack-2.3.4-1mdv2010.0.noarch.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActionController::Assertions::RoutingAssertions</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActionController::Assertions::RoutingAssertions</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/lib/action_controller/assertions/routing_assertions_rb.html">
                lib/action_controller/assertions/routing_assertions.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Suite of assertions to test routes generated by Rails and the handling of
requests made to them.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000215">assert_generates</a>&nbsp;&nbsp;
      <a href="#M000214">assert_recognizes</a>&nbsp;&nbsp;
      <a href="#M000216">assert_routing</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000215" class="method-detail">
        <a name="M000215"></a>

        <div class="method-heading">
          <a href="RoutingAssertions.src/M000215.html" target="Code" class="method-signature"
            onclick="popupCode('RoutingAssertions.src/M000215.html');return false;">
          <span class="method-name">assert_generates</span><span class="method-args">(expected_path, options, defaults={}, extras = {}, message=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts that the provided options can be used to generate the provided
path. This is the inverse of <tt><a
href="RoutingAssertions.html#M000214">assert_recognizes</a></tt>. The
<tt>extras</tt> parameter is used to tell the request the names and values
of additional request parameters that would be in a query string. The
<tt>message</tt> parameter allows you to specify a custom error message for
assertion failures.
</p>
<p>
The <tt>defaults</tt> parameter is unused.
</p>
<h4>Examples</h4>
<pre>
  # Asserts that the default action is generated for a route with no action
  assert_generates &quot;/items&quot;, :controller =&gt; &quot;items&quot;, :action =&gt; &quot;index&quot;

  # Tests that the list action is properly routed
  assert_generates &quot;/items/list&quot;, :controller =&gt; &quot;items&quot;, :action =&gt; &quot;list&quot;

  # Tests the generation of a route with a parameter
  assert_generates &quot;/items/list/1&quot;, { :controller =&gt; &quot;items&quot;, :action =&gt; &quot;list&quot;, :id =&gt; &quot;1&quot; }

  # Asserts that the generated route gives us our custom route
  assert_generates &quot;changesets/12&quot;, { :controller =&gt; 'scm', :action =&gt; 'show_diff', :revision =&gt; &quot;12&quot; }
</pre>
        </div>
      </div>

      <div id="method-M000214" class="method-detail">
        <a name="M000214"></a>

        <div class="method-heading">
          <a href="RoutingAssertions.src/M000214.html" target="Code" class="method-signature"
            onclick="popupCode('RoutingAssertions.src/M000214.html');return false;">
          <span class="method-name">assert_recognizes</span><span class="method-args">(expected_options, path, extras={}, message=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts that the routing of the given <tt>path</tt> was handled correctly
and that the parsed options (given in the <tt>expected_options</tt> hash)
match <tt>path</tt>. Basically, it asserts that Rails recognizes the route
given by <tt>expected_options</tt>.
</p>
<p>
Pass a hash in the second argument (<tt>path</tt>) to specify the request
method. This is useful for routes requiring a specific HTTP method. The
hash should contain a :path with the incoming request path and a :method
containing the required HTTP verb.
</p>
<pre>
  # assert that POSTing to /items will call the create action on ItemsController
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'create'}, {:path =&gt; 'items', :method =&gt; :post}
</pre>
<p>
You can also pass in <tt>extras</tt> with a hash containing URL parameters
that would normally be in the query string. This can be used to assert that
values in the query string string will end up in the params hash correctly.
To test query strings you must use the extras argument, appending the query
string on the path directly will not work. For example:
</p>
<pre>
  # assert that a path of '/items/list/1?view=print' returns the correct options
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'list', :id =&gt; '1', :view =&gt; 'print'}, 'items/list/1', { :view =&gt; &quot;print&quot; }
</pre>
<p>
The <tt>message</tt> parameter allows you to pass in an error message that
is displayed upon failure.
</p>
<h4>Examples</h4>
<pre>
  # Check the default route (i.e., the index action)
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'index'}, 'items'

  # Test a specific action
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'list'}, 'items/list'

  # Test an action with a parameter
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'destroy', :id =&gt; '1'}, 'items/destroy/1'

  # Test a custom route
  assert_recognizes {:controller =&gt; 'items', :action =&gt; 'show', :id =&gt; '1'}, 'view/item1'

  # Check a Simply RESTful generated route
  assert_recognizes list_items_url, 'items/list'
</pre>
        </div>
      </div>

      <div id="method-M000216" class="method-detail">
        <a name="M000216"></a>

        <div class="method-heading">
          <a href="RoutingAssertions.src/M000216.html" target="Code" class="method-signature"
            onclick="popupCode('RoutingAssertions.src/M000216.html');return false;">
          <span class="method-name">assert_routing</span><span class="method-args">(path, options, defaults={}, extras={}, message=nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Asserts that path and options match both ways; in other words, it verifies
that <tt>path</tt> generates <tt>options</tt> and then that
<tt>options</tt> generates <tt>path</tt>. This essentially combines <tt><a
href="RoutingAssertions.html#M000214">assert_recognizes</a></tt> and <tt><a
href="RoutingAssertions.html#M000215">assert_generates</a></tt> into one
step.
</p>
<p>
The <tt>extras</tt> hash allows you to specify options that would normally
be provided as a query string to the action. The <tt>message</tt> parameter
allows you to specify a custom error message to display upon failure.
</p>
<h4>Examples</h4>
<pre>
 # Assert a basic route: a controller with the default action (index)
 assert_routing '/home', :controller =&gt; 'home', :action =&gt; 'index'

 # Test a route generated with a specific controller, action, and parameter (id)
 assert_routing '/entries/show/23', :controller =&gt; 'entries', :action =&gt; 'show', id =&gt; 23

 # Assert a basic route (controller + default action), with an error message if it fails
 assert_routing '/store', { :controller =&gt; 'store', :action =&gt; 'index' }, {}, {}, 'Route for store index not generated properly'

 # Tests a route, providing a defaults hash
 assert_routing 'controller/action/9', {:id =&gt; &quot;9&quot;, :item =&gt; &quot;square&quot;}, {:controller =&gt; &quot;controller&quot;, :action =&gt; &quot;action&quot;}, {}, {:item =&gt; &quot;square&quot;}

 # Tests a route with a HTTP method
 assert_routing { :method =&gt; 'put', :path =&gt; '/product/321' }, { :controller =&gt; &quot;product&quot;, :action =&gt; &quot;update&quot;, :id =&gt; &quot;321&quot; }
</pre>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>