This project is archived and is in readonly mode.

#6167 needs-more-info
petRUShka

Strange behaviour of assert_redirected_to

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

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

Comments and changes to this ticket

  • Andrew White

    Andrew White February 14th, 2011 @ 12:26 PM

    • 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

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages