Topic: functional test assert_redirect_to

routes.rb

  map.resources :places do |places|
      places.resources :reviews  
  end
 

place model

class Place < ActiveRecord::Base
  has_many :reviews
end

review model

class Review < ActiveRecord::Base
  belongs_to :place
end

In my reviews controller test I have the following assert_redirect_to statement

assert_redirected_to place_review_path(assigns(:place), assigns(:review))

but functional test fail with the following error

  1) Failure:
test_should_create_review(ReviewsControllerTest) [/test/functional/reviews_controller_test.rb:24]:
Expected response to be a redirect to <http://test.host/places/980190962/reviews/980190963> but was a redirect to <http://test.host/places/980190962>.

  2) Failure:
test_should_destroy_review(ReviewsControllerTest) [/test/functional/reviews_controller_test.rb:47]:
Expected response to be a redirect to <http://test.host/places/980190962/reviews.%23%3Creview:0xb74783a0%3E> but was a redirect to <http://test.host/places/980190962/reviews>.

  3) Failure:
test_should_update_review(ReviewsControllerTest) [/test/functional/reviews_controller_test.rb:39]:
Expected response to be a redirect to <http://test.host/places/980190962/reviews/980190962> but was a redirect to <http://test.host/places/980190962>.

What could be causing this problem?

Re: functional test assert_redirect_to

I believe your routes are wrong. Try this:

map.resources :places do |place|
  place.resources :reviews  
end