1 == Add a Custom Route ==
3 Testing routes in plugins can be complex, especially if the controllers are also in the plugin itself. Jamis Buck showed a great example of this in http://weblog.jamisbuck.org/2006/10/26/monkey-patching-rails-extending-routes-2.
5 *vendor/plugins/yaffle/test/routing_test.rb*
8 --------------------------------------------------------
9 require "#{File.dirname(__FILE__)}/test_helper"
11 class RoutingTest < Test::Unit::TestCase
14 ActionController::Routing::Routes.draw do |map|
19 def test_yaffles_route
20 assert_recognition :get, "/yaffles", :controller => "yaffles_controller", :action => "index"
25 # yes, I know about assert_recognizes, but it has proven problematic to
26 # use in these tests, since it uses RouteSet#recognize (which actually
27 # tries to instantiate the controller) and because it uses an awkward
29 def assert_recognition(method, path, options)
30 result = ActionController::Routing::Routes.recognize_path(path, :method => method)
31 assert_equal options, result
34 --------------------------------------------------------
36 *vendor/plugins/yaffle/init.rb*
39 --------------------------------------------------------
41 ActionController::Routing::RouteSet::Mapper.send :include, Yaffle::Routing::MapperExtensions
42 --------------------------------------------------------
44 *vendor/plugins/yaffle/lib/routing.rb*
47 --------------------------------------------------------
48 module Yaffle #:nodoc:
49 module Routing #:nodoc:
50 module MapperExtensions
52 @set.add_route("/yaffles", {:controller => "yaffles_controller", :action => "index"})
57 --------------------------------------------------------
62 --------------------------------------------------------
63 ActionController::Routing::Routes.draw do |map|
67 --------------------------------------------------------
69 You can also see if your routes work by running `rake routes` from your app directory.