title: Why is Rails not giving a 3XX on redirect and causing my unit tests to fail?
body: <p>I'm trying out some unit tests for the first time in Ruby on Rails 5.0.1 (designed sites a few times without tests but just starting to understand the value of proper testing...) and writing a sample app to get the hang of things. I have written some tests to make sure the routing works correctly.</p>
  
  <p><strong>test/controllers/static_page_controllers_test</strong></p>
  
  <pre><code>require 'test_helper'
  
  class StaticPagesControllerTest &lt; ActionDispatch::IntegrationTest
    test "root should get static_pages home" do
      get '/'
      assert_redirected_to static_pages_home_url
    end
  
    test "static_pages root should get static_pages home" do
      get '/static_pages'
      assert_redirected_to static_pages_home_url
    end
  
    [some other tests]
  
  end
  </code></pre>
  
  <p>I have written some routing code to redirect from root and <code>static_pages</code> root to the <code>static_pages</code> <code>home</code> embedded ruby html file. This code does correctly redirect in the sense that when you point the browser at <code>/static_pages</code> or <code>/</code> the <code>static_pages/home.html.erb</code> page loads.</p>
  
  <p><strong>app/config/routes.rb</strong></p>
  
  <pre><code>Rails.application.routes.draw do
    get '/static_pages' =&gt; 'static_pages#home'
    get 'static_pages/home'
    get 'static_pages/help'
    get 'static_pages/about'
    root 'static_pages#home'
  end
  </code></pre>
  
  <p>When I run my unit tests for redirects they are still failing.</p>
  
  <p><strong><code>rails test</code></strong></p>
  
  <pre><code># Running:
  
  F
  
  Failure:
  StaticPagesControllerTest#test_root_should_get_static_pages_home [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:6]:
  Expected response to be a &lt;3XX: redirect&gt;, but was a &lt;200: OK&gt;
  
  
  bin/rails test test/controllers/static_pages_controller_test.rb:4
  
  ..F
  
  Failure:
  StaticPagesControllerTest#test_static_pages_root_should_get_static_pages_home [/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:11]:
  Expected response to be a &lt;3XX: redirect&gt;, but was a &lt;200: OK&gt;
  
  
  bin/rails test test/controllers/static_pages_controller_test.rb:9
  
  .
  
  Finished in 0.821392s, 6.0872 runs/s, 6.0872 assertions/s.
  
  5 runs, 5 assertions, 2 failures, 0 errors, 0 skips
  </code></pre>
  
  <p>A quick <code>wget</code> to the root URL confirms the Rails Puma server is returning HTTP 200 instead of a 300. Do I need to manually alter the HTTP requests themselves or am I handling the redirect wrongly in some manner? How best to change this so my unit tests work correctly and the server returns the right HTTP status code?</p>