Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Strange behaviour of assert_redirected_to

#6167

I have such lines in routes.rb:

resource :order
match '/' => 'orders#new', :constraints => { :subdomain => /.+/ }

And in controller I have:

redirect_to new_order_path(:subdomain => current_subdomain)

And I write such test:

@request.host = "subdomain." + @request.host
get :test
assert_redirected_to(:action => :new)

So I get an error:

Expected response to be a redirect to <http://subdomain.test.host/> but was a redirect to <http://subdomain.test.host/order/new>

If I delete match '/' from routes it is ok.

I think that new_order_path can recognize that it is / but redirect_to can't.

Rails 3, Ruby 1.9.

subdomain realisation from railscast: http://railscasts.com/episodes/221-subdomains-in-rails-3

Reported by petRUShka · December 15th, 2010 @ 08:42 AM

State: needs-more-info
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • State changed from new to needs-more-info
    • Importance changed from to Low

    Not quite sure what you're trying to achieve here - the examples you've posted are quite different to the railscast. The named url helper new_order_path will always generate the full path '/order/new' and won't match the assert_redirected_to.

    Are you trying to redirect a request from a default url to a subdomain url or the other way around

    February 14th, 2011 @ 12:26 PM