# Absolute urls don't work in functional tests (with 'fix')

**URL:** <https://www.ruby-forum.com/t/absolute-urls-dont-work-in-functional-tests-with-fix/67740>\
**Category:** Rails\
**Created:** [September 6, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/absolute-urls-dont-work-in-functional-tests-with-fix/67740 "2006-09-06T14:41:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_del\_Stroth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@Jonathan\_del\_Stroth](https://www.ruby-forum.com/u/Jonathan_del_Stroth)\
**Post date:** [September 6, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/absolute-urls-dont-work-in-functional-tests-with-fix/67740/1 "2006-09-06T14:41:55Z")

</div>

Why is it that I can’t do “get posts\_url” in my post functional  
testing? posts\_url correctly evaluates to “[http://test.host/](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](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](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](http://weenie.net/tip/2006/7/22/test-named-routes-or-url_for-link_to))

---

<div class="post-metadata">

**Author:** ![Jonathan\_del\_Stroth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@Jonathan\_del\_Stroth](https://www.ruby-forum.com/u/Jonathan_del_Stroth)\
**Post date:** [September 6, 2006, 4:36pm UTC](https://www.ruby-forum.com/t/absolute-urls-dont-work-in-functional-tests-with-fix/67740/2 "2006-09-06T16:36:12Z")

</div>

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](http://test.host/posts/6)”)

Any other bright ideas?
