Early on in my exploration of Rails, I got into the habit of testing that the response code of an action indicated a redirect. It turns out that this check is entirely unnecessary since assert_redirected_to
makes an identical check:
def assert_redirected_to(options = {}, message=nil) clean_backtrace do assert_response(:redirect, message) ... end end
This is how one of my functional tests might have looked early on:
def test_index get :index assert_response :redirect assert_redirected_to :action => "list" end
This is how the test should be written now:
def test_index get :index assert_redirected_to :action => "list" end
I recall reading several examples that specifically checked for a :redirect
response code before calling assert_redirected_to
so it must have been necessary at some point. It’s certainly not necessary anymore. Keep this in mind and save yourself a line or two of code.