Jonathan del Strother
2006-Sep-06 12:17 UTC
Absolute urls don''t work in functional tests (with ''fix'')
Why is it that I can''t do "get posts_url" in my post functional testing? posts_url correctly evaluates to "http://test.host/ posts" (*), but any attempt to get this url fails with an UnknownAction. Similarly, "get ''/posts''", "get ''/posts/index''" etc all fail. "get ''index''" works fine. Which may sound trivial, but it seems silly to not be able to use "get new_post_url" with your restful controllers. The main reason it''s falling over seems to be that the TestProcess module is very action-based - it doesn''t expect to see the full "http://test.host/posts/index" url. I''ve hacked in a workaround that strips out everything but the action: module ActionController::TestProcess alias_method :orig_process, :process def process(action, parameters = nil, session = nil, flash = nil) #Strip out occurrences of (eg) ''http://test.host/posts'', leaving us with just the action. nameless_action = action.to_s.gsub(/http:\/\/# {@request.host_with_port}\/#{@controller.class.controller_path}\/?/, '''') nameless_action = ''index'' if nameless_action.blank? orig_process(nameless_action, parameters, session, flash) end end - but it''s pretty ugly, and I suspect it''ll break on all but the simplest routes. Can anyone else do better? Jon * - once you''ve done the "get :index" hack - http://rails.techno- weenie.net/tip/2006/7/22/test-named-routes-or-url_for-link_to) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jonathan del Strother
2006-Sep-06 14:09 UTC
Re: Absolute urls don''t work in functional tests (with ''fix'')
On 6 Sep 2006, at 13:17, Jonathan del Strother wrote:> Why is it that I can''t do "get posts_url" in my post functional > testing? posts_url correctly evaluates to "http://test.host/ > posts" (*), but any attempt to get this url fails with an > UnknownAction. Similarly, "get ''/posts''", "get ''/posts/index''" etc > all fail. "get ''index''" works fine. > > Which may sound trivial, but it seems silly to not be able to use > "get new_post_url" with your restful controllers. > > The main reason it''s falling over seems to be that the TestProcess > module is very action-based - it doesn''t expect to see the full > "http://test.host/posts/index" url. I''ve hacked in a workaround that > strips out everything but the action: > > > module ActionController::TestProcess > alias_method :orig_process, :process > def process(action, parameters = nil, session = nil, flash = nil) > #Strip out occurrences of (eg) ''http://test.host/posts'', leaving > us with just the action. > nameless_action = action.to_s.gsub(/http:\/\/# > {@request.host_with_port}\/#{@controller.class.controller_path} > \/?/, '''') > nameless_action = ''index'' if nameless_action.blank? > orig_process(nameless_action, parameters, session, flash) > end > end > > - but it''s pretty ugly, and I suspect it''ll break on all but the > simplest routes. Can anyone else do better?Hmph, well that doesn''t work. It falls over on a number of restful things like post_url(@post) ("http://test.host/posts/6") Any other bright ideas? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---