Permalink
Browse files

Generate routes for nested resources with nil object raise RoutingErr…

…or [#4262 state:committed]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
1 parent 1d73682 commit cfb31edb5441f0b12693a3b509dadf87fe1df843 @spastorino spastorino committed with jeremy Apr 7, 2010
@@ -174,6 +174,7 @@ def define_url_helper(route, name, kind, options)
#
named_helper_module_eval <<-end_eval # We use module_eval to avoid leaks
def #{selector}(*args) # def users_url(*args)
+ args.compact! #
#
#{generate_optimisation_block(route, kind)} # #{generate_optimisation_block(route, kind)}
#
@@ -566,6 +566,10 @@ def show
render :inline => "<%= url_for([@workshop, @session]) %>\n<%= link_to('Session', [@workshop, @session]) %>"
end
+ def show_workshop_of_nil_sessions
+ render :inline => "<%= workshop_sessions_path(nil) %>"
+ end
+
def rescue_action(e) raise e end
end
@@ -612,13 +616,24 @@ def test_existing_nested_resource
end
end
+ def test_existing_nested_resource_with_nil_id
+ @controller = SessionsController.new
+
+ with_restful_routing do
+ assert_raise ActionController::RoutingError do
+ get :show_workshop_of_nil_sessions
+ end
+ end
+ end
+
protected
def with_restful_routing
with_routing do |set|
set.draw do |map|
map.resources :workshops do |w|
w.resources :sessions
end
+ map.show_workshop_of_nil_sessions 'sessions/show_workshop_of_nil_sessions', :controller => 'sessions', :action => 'show_workshop_of_nil_sessions'
end
yield
end

0 comments on commit cfb31ed

Please sign in to comment.