title: Rails responds with status code 406
body: <p>I have been working on a test for my function inside Ruby on Rails. However, the test (which expects a status code of <code>:success</code>) fails after receiving a status code <code>406</code>. Here's the exact failure log:</p>
  
  <pre><code>Failure: Expected response to be a &lt;:success&gt;, but was &lt;406&gt;.
  test_should_post_comment_through_token_successfully(CommentControllerTest)
  test/functional/comment_controller_test.rb:271:in `block in &lt;class:CommentControllerTest&gt;'
  </code></pre>
  
  <p>I read a little about the <code>406</code> response, and found out that it stands of "Not Acceptable". so I tried setting the <code>Accept</code>, <code>Content-Type</code>, <code>Accept-Language</code> and <code>Accept-Charset</code> headers but I have had no luck.</p>
  
  <p>Here's the code for my test:</p>
  
  <pre><code>test 'should post comment through token successfully' do
    @params = {
      id: 1,
      body: "Test Comment",
      username: "Bob"
    }
  
    @headers = {
      "Accept" =&gt; "application/json",
      "Accept-Language" =&gt; "en-US",
      "Accept-Charset" =&gt; "utf-8",
      "Content-Type" =&gt; "application/json",
      "Token" =&gt; "abcdefg12345"
    }
  
    get :create_by_token, @params, @headers
    assert_response :success
  end
  </code></pre>
  
  <p>The <code>create_by_token</code> function inside the controller:</p>
  
  <pre><code>def create_by_token
    @node = Node.find params[:id]
    @user = User.find_by_username params[:username]
    @body = params[:body]
    @token = request.headers['Token']
    p request.headers["Accept"]
    p request.headers["Content-Type"]
    p request.headers["Token"]
  
    if @user &amp;&amp; @user.token == @token
      begin
        @comment = create_comment(@node, @user, @body)
        msg = {
          status: :created,
          message: "Created"
        }
        respond_to do |format|
          format.xml { render xml: msg.to_xml }
          format.json { render json: msg.to_json }
        end
      rescue CommentError
        msg = {
          status: :bad_request,
          message: "Bad Request"
        }
        respond_to do |format|
          format.xml { render xml: msg.to_xml }
          format.json { render json: msg.to_json }
        end
      end
    else
      msg = {
        status: :unauthorized,
        message: "Unauthorized"
      }
      respond_to do |format|
        format.xml { render xml: msg.to_xml }
        format.json { render json: msg.to_json }
      end
    end
  end
  </code></pre>
  
  <p>My route:</p>
  
  <pre><code>post '/bot/comment.:format', to: 'comment#create_by_token'
  </code></pre>
  
  <p>Am I missing something crucial? How do I go about solving this issue?</p>
  
  <p>I would be happy to provide any other information you would need.</p>