0

郵便配達員またはカール投稿が正常に機能するという奇妙な状況があります。たとえば、以下は期待どおりに機能し、新しいレコードを作成します。

curl -X POST \                                   
  -H "Content-Type: application/vnd.api+json" \
  -H "Accept: application/vnd.api+json" \
  -d '{
  "data": {
    "type": "drivers",
    "attributes": {
      "firstname": "John",
      "lastname": "Doe",
      "age": "24",
      "status": "pending"
    }
  }
}' "http://localhost:3000/api/v1/drivers"

しかし、以下のように RSpec リクエスト仕様を介してアクセスしようとすると、ステータス 400 (BadRequest) が表示されます。

...
describe "POST /api/v1/drivers" do
  context 'valid data' do 
    it 'saves valid data' do
      headers = { 
        "Content-Type" => "application/vnd.api+json",
        "Accept" => "application/vnd.api+json " 
      }

      post api_v1_drivers_path, params: {
        data: {
          type: 'drivers',
          attributes: {
            firstname: 'John',
            lastname: 'Doe',
            age: 24,
            status: 'pending'
          }
        }
      }, headers: headers

      expect(response).to have_http_status(201)
    end
  end
end

この問題に遭遇しましたか? 明らかな何かが欠けていますか?フィードバックは大歓迎です。

4

1 に答える 1