samedi 6 août 2016

rails api testing json response

I have a 4.2.5 rails api and I guess I get this error thanks to the extracted responders. What should I change to make it work?

error:

1) Error:
Api::V1::GraphControllerTest#test_should_get_show:
ActionController::UnknownFormat: ActionController::UnknownFormat
    app/controllers/api/v1/graph_controller.rb:7:in `show'
    test/controllers/api/v1/graph_controller_test.rb:5:in `block in <class:GraphControllerTest>'

controller

class Api::V1::CategoryController < ApplicationController
  def show
    category = params[:category] || "sports"
    @category = Category.where(cat_title: category.capitalize).first
    respond_to do |format|
      format.json { render json: @category, serializer: CategorySerializer, root: "category" }
    end
  end
end

Test

require 'test_helper'

class Api::V1::CategoryControllerTest < ActionController::TestCase
  test "should get show" do 
    get :show, {'category' => 'science'}, format: :json
    assert_response :success
    assert_equal "{\"category\":{\"title\":\"science\",\"sub_categories\":1}}", @response.body
  end
end

Aucun commentaire:

Enregistrer un commentaire