write ahead log

ロールフォワード用

Rails5でJSON APIをテストする

知らないとハマる.

JSONのAPIに以下の様にしてアクセスしようとすると.

get order_detail_path(@buy_new_computer)
assert_response :success

UnknownFormatと言われる.

ActionController::UnknownFormat: ActionController::UnknownFormat
    app/controllers/order_details_controller.rb:7:in `show'
        test/controllers/order_details_controller_test.rb:30:in `block in <class:OrderDetailsControllerTest>'

調べるとjsonを取得する際は asでの指定が必要らしい.

#get order_detail_path(@buy_new_computer), as: :json
get order_detail_path(@buy_new_computer)
assert_response :success

参考

助かりました....

RailsのテストでJSON形式のデータを取得する