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

On 6 Sep 2006, at 13:17, Jonathan del Strother wrote:

module is very action-based - it doesn’t expect to see the full
{@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?