views:

325

answers:

3

I have a rails application which acts differently depending on what domain it's accessed at (for example www.myapp.com will invoke differently to user.myapp.com). In production use this all works fine but my test code always sees a hostname of "www.example.com".

Is there a clean way of having a test specify the hostname it's pretending to access?

A: 

I believe you can modify the HTTP_HOST or SERVER_NAME environment vars to change the request that goes to the router:

ENV['SERVER_NAME'] = "user.myapp.com"

See raw_host_with_port in actionpack/lib/action_controller/request.rb.

Dave Ray
+3  A: 
@request.host = 'user.myapp.com'
jcrossley3
A: 

@request.host = 'user.myapp.com' is not right. should use !host(www.myapp.com)

Ian