Rails Integration Test assert redirected_to :back

Published on Sep 02, 2016 - Last updated on Dec 10, 2016

share comments

Given a controller action that performs a redirect_to :back, and a test that inherits from ActionDispatch::IntegrationTest and tries toassert_redirected_to previous url, we can do the following:

                        test 'put update object' do
                        put update_object_path(object), {}, { 'HTTP_REFERER' => ‘path_to_be_redirected_to' }
                        assert_redirected_to path_to_be_redirected_to

Then we must only adjust path_to_be_redirected_to to that previous url we want.

Category: Ruby On Rails