RspecでAPIテストするときの注意点です。
下記のようにリクエストパラメータをベタ書きしているときは、postリクエストのオプションでrequest_header情報をつけないと、正しく認識されないようです。リクエストパラメータの書き方を変更すれば、header情報はいらないようですが。
let(:request_header) do { 'CONTENT_TYPE' => 'application/json', 'ACCEPT' => 'application/json' } end let(:user) do '{"name": "testuser", "profile": "testuser", "email": "user1@test.com", "password": "testtesttest", "password_confirmation": "testtesttest", "sex": "male", "birth_date": "2000-01-01 00:00:00", "agreement": "1", "telephone_number": "000-1111-2222", "address1": "住所1", "address2": "住所2", "status": "active", "pay_type": "CreditCard"}' end subject do post api_v1_users_create_path(format: :json), user, request_header end
コメントを残す