Skip to content

Instantly share code, notes, and snippets.

@matthewtodd
Created February 27, 2009 07:59
Show Gist options
  • Save matthewtodd/71344 to your computer and use it in GitHub Desktop.
Save matthewtodd/71344 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'action_controller'
require 'test/unit'
class AccountsController < ActionController::Base
end
# Your mission, should you choose to accept it: Change the RouteSet (in the
# with_route_set method) so as to make both tests pass.
class RoutingTest < ActionController::TestCase
def test_named_route
with_route_set do
assert_routing '/accounts/new', hash_for_named_route(:new_account)
end
end
def test_named_route_adding_an_optional_parameter
with_route_set do
assert_routing '/accounts/new/CODE', hash_for_named_route(:new_account).merge(:account => { :invitation_code => 'CODE'})
end
end
private
def hash_for_named_route(named_route)
send("hash_for_#{named_route}_path").except(:only_path, :use_route)
end
def with_route_set
with_routing do |set|
set.draw do |map|
# You're free to change from here...
map.resources :accounts
# ... to here. That's it.
end
begin
set.named_routes.install(metaclass)
yield
ensure
# We should find a way to "uninstall" the named routes here.
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment