このコミットが含まれているのは:
@@ -2,20 +2,18 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe 'error responses', type: :request do
|
||||
describe 'manual input errors' do
|
||||
it 'returns a stable errors array for bad requests' do
|
||||
user = create(:user)
|
||||
sign_in_as(user)
|
||||
|
||||
put "/users/#{ user.id }", params: { name: ' ' }
|
||||
it 'returns a stable payload for bad requests' do
|
||||
get '/tags/name/%20/deerjikists'
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(json.fetch('errors')).to contain_exactly(
|
||||
include('code' => 'bad_request',
|
||||
'field' => 'name',
|
||||
'message' => be_present))
|
||||
expect(json).to include(
|
||||
'type' => 'bad_request',
|
||||
'message' => be_present,
|
||||
'errors' => {},
|
||||
'base_errors' => [be_present])
|
||||
end
|
||||
|
||||
it 'returns a stable errors array for unprocessable requests' do
|
||||
it 'returns a stable field-error payload for unprocessable requests' do
|
||||
member = create(:user, :member)
|
||||
tag = create(:tag, :general, name: 'error_response_tag')
|
||||
sign_in_as(member)
|
||||
@@ -23,25 +21,27 @@ RSpec.describe 'error responses', type: :request do
|
||||
patch "/tags/#{ tag.id }", params: { category: 'nico' }
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to contain_exactly(
|
||||
include('code' => 'invalid',
|
||||
'field' => 'category',
|
||||
'message' => be_present))
|
||||
expect(json).to include(
|
||||
'type' => 'validation_error',
|
||||
'message' => '入力内容を確認してください.',
|
||||
'base_errors' => [])
|
||||
expect(json.fetch('errors')).to include(
|
||||
'category' => ['ニコタグは変更できません.'])
|
||||
end
|
||||
end
|
||||
|
||||
describe 'model validation errors' do
|
||||
it 'returns field, code, and message for model errors' do
|
||||
it 'returns field messages for model errors' do
|
||||
user = create(:user)
|
||||
sign_in_as(user)
|
||||
|
||||
put "/users/#{ user.id }", params: { name: 'a' * 256 }
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
include('code' => 'too_long',
|
||||
'field' => 'name',
|
||||
'message' => be_present))
|
||||
expect(json).to include(
|
||||
'type' => 'validation_error',
|
||||
'message' => '入力内容を確認してください.')
|
||||
expect(json.fetch('errors').fetch('name')).to include(be_present)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -141,16 +141,21 @@ RSpec.describe 'Materials API', type: :request do
|
||||
context 'when logged in' do
|
||||
before { sign_in_as(guest_user) }
|
||||
|
||||
it 'returns 400 when tag is blank' do
|
||||
it 'returns 422 when tag is blank' do
|
||||
post '/materials', params: { tag: ' ', file: dummy_upload }
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tag' => ['タグは必須です.'])
|
||||
end
|
||||
|
||||
it 'returns 400 when both file and url are blank' do
|
||||
it 'returns 422 when both file and url are blank' do
|
||||
post '/materials', params: { tag: 'material_create_blank' }
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'file' => ['ファイルまたは URL は必須です.'],
|
||||
'url' => ['ファイルまたは URL は必須です.'])
|
||||
end
|
||||
|
||||
it 'creates a material with an attached file' do
|
||||
@@ -261,21 +266,26 @@ RSpec.describe 'Materials API', type: :request do
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'returns 400 when tag is blank' do
|
||||
it 'returns 422 when tag is blank' do
|
||||
put "/materials/#{ material.id }", params: {
|
||||
tag: ' ',
|
||||
file: dummy_upload
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tag' => ['タグは必須です.'])
|
||||
end
|
||||
|
||||
it 'returns 400 when both file and url are blank' do
|
||||
it 'returns 422 when both file and url are blank' do
|
||||
put "/materials/#{ material.id }", params: {
|
||||
tag: 'material_update_no_payload'
|
||||
}
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'file' => ['ファイルまたは URL は必須です.'],
|
||||
'url' => ['ファイルまたは URL は必須です.'])
|
||||
end
|
||||
|
||||
it 'updates tag, url, file, and updated_by_user' do
|
||||
|
||||
@@ -75,7 +75,7 @@ RSpec.describe 'NicoTags', type: :request do
|
||||
expect(versions.last.created_by_user_id).to eq(admin.id)
|
||||
end
|
||||
|
||||
it '400 when linked tag normalises to nico tag' do
|
||||
it 'returns 422 when linked tag normalises to nico tag' do
|
||||
sign_in_as(member)
|
||||
|
||||
other_nico = create(:tag, :nico, name: 'nico:linked_ng')
|
||||
@@ -87,7 +87,9 @@ RSpec.describe 'NicoTags', type: :request do
|
||||
patch "/tags/nico/#{nico_tag.id}", params: { tags: 'linked_ng_alias' }
|
||||
}.not_to change(NicoTagVersion, :count)
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tags' => ['ニコニコ・タグ同士は連携できません.'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -704,7 +704,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
category: :nico)
|
||||
end
|
||||
|
||||
it 'return 400' do
|
||||
it 'returns 422 with tag field errors' do
|
||||
sign_in_as(member)
|
||||
|
||||
post '/posts', params: post_write_params(
|
||||
@@ -714,7 +714,13 @@ RSpec.describe 'Posts API', type: :request do
|
||||
thumbnail: dummy_upload
|
||||
)
|
||||
|
||||
expect(response).to have_http_status(:bad_request), response.body
|
||||
expect(response).to have_http_status(:unprocessable_entity), response.body
|
||||
expect(json).to include(
|
||||
'type' => 'validation_error',
|
||||
'message' => '入力内容を確認してください.',
|
||||
'base_errors' => [])
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tags' => ['ニコニコ・タグは直接指定できません.'])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -931,7 +937,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
category: :nico)
|
||||
end
|
||||
|
||||
it 'return 400' do
|
||||
it 'returns 422 with tag field errors' do
|
||||
sign_in_as(member)
|
||||
|
||||
put "/posts/#{post_record.id}", params: post_update_params(
|
||||
@@ -939,7 +945,13 @@ RSpec.describe 'Posts API', type: :request do
|
||||
title: 'updated title',
|
||||
tags: 'nico:nico_tag')
|
||||
|
||||
expect(response).to have_http_status(:bad_request), response.body
|
||||
expect(response).to have_http_status(:unprocessable_entity), response.body
|
||||
expect(json).to include(
|
||||
'type' => 'validation_error',
|
||||
'message' => '入力内容を確認してください.',
|
||||
'base_errors' => [])
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tags' => ['ニコニコ・タグは直接指定できません.'])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -275,6 +275,30 @@ RSpec.describe 'Tags deerjikists API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a row is invalid' do
|
||||
let(:payload) do
|
||||
[
|
||||
{ platform: '', code: code1 },
|
||||
]
|
||||
end
|
||||
|
||||
it 'returns 422 with indexed field errors and does not replace existing deerjikists' do
|
||||
Deerjikist.create!(platform: platform1, code: code1, tag: tag)
|
||||
|
||||
expect {
|
||||
do_request
|
||||
}.not_to change { Deerjikist.where(tag: tag).map { |d| [d.platform, d.code] } }
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json).to include(
|
||||
'type' => 'validation_error',
|
||||
'message' => '入力内容を確認してください.',
|
||||
'base_errors' => [])
|
||||
expect(json.fetch('errors')).to include(
|
||||
'deerjikists.0.platform' => [be_present])
|
||||
end
|
||||
end
|
||||
|
||||
context 'when youtube code is handle' do
|
||||
let(:channel_id) { 'UCabcdefghijklmnopqrstuv' }
|
||||
let(:payload) do
|
||||
|
||||
@@ -90,12 +90,14 @@ RSpec.describe 'Users', type: :request do
|
||||
expect(response).to have_http_status(:unauthorized)
|
||||
end
|
||||
|
||||
it 'returns 400 when name is blank' do
|
||||
it 'returns 422 when name is blank' do
|
||||
put "/users/#{user.id}",
|
||||
params: { name: ' ' },
|
||||
headers: auth_headers(user)
|
||||
|
||||
expect(response).to have_http_status(:bad_request)
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'name' => ['名前は必須です.'])
|
||||
end
|
||||
|
||||
it 'updates name and returns user slice' do
|
||||
|
||||
新しい課題から参照
ユーザをブロックする